viclafouch / mui-chips-input

📌 A chips input designed for MUI (Material ui) V6
https://viclafouch.github.io/mui-chips-input/
MIT License
83 stars 19 forks source link

Input does not clear on blur event when tabbing to next field #16

Closed bmccaw closed 1 year ago

bmccaw commented 1 year ago

Describe the bug With clearInputOnBlur set to true, the input does not clear when the user tabs out of the input into the next field.

To Reproduce Steps to reproduce the behavior:

  1. Set clearInputOnBlur prop to 'true'
  2. Enter a value into the input.
  3. Press Tab to move to the next input field.
  4. Chip gets added but value remains in input.

Expected behavior I would assume that a tab event would function the same as the user clicking outside of the input and the input would clear.

Screenshots InkedScreenshot 2023-01-30 at 10 58 14 AM

Desktop (please complete the following information):

sljricardo commented 1 year ago

I had the same problem, and by using useState to manage the inputValue you can achieve the behavior you want

try this and see if helps

const ChipsInput = ({ label, tip, ...rest }: ChipsInputType) => {
  const classes = useStyles();
  const [inputValue, setInputValue] = useState("");

  const handleOnBlurChips = ({ target }) => {
    rest.onAddChip(target.value, rest.value.length + 1);
    setInputValue("");
  };

  return (
    <MuiChipsInput
      placeholder={""}
      className={classes.root}
      variant="outlined"
      onBlur={handleOnBlurChips}
      onInputChange={setInputValue}
      inputValue={inputValue}
      {...rest}
    />
  );
};
viclafouch commented 1 year ago

Hey @bmccaw ! Thanks for the catch !

The fix has been released in the v1.3.3 ;)