Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to control inputValue #5

Closed
Elfayer opened this issue Sep 24, 2022 · 1 comment
Closed

Need to control inputValue #5

Elfayer opened this issue Sep 24, 2022 · 1 comment

Comments

@Elfayer
Copy link

Elfayer commented Sep 24, 2022

Is your feature request related to a problem? Please describe.
I want to have a scan input, for that I use a debounce on the onInputChange, when 300ms passed, I set the chips. But after that, I need to reset the input value (but I do not have control over inputValue, see: https://github.com/viclafouch/mui-chips-input/blob/main/src/components/TextFieldChip/TextFieldChips.tsx#L66)

Describe the solution you'd like
Need to have inputValue as props of MuiChipsInput.

Code usage sample

export default function ScanForm() {
  const [chips, setChips] = useState<string[]>([])
  const [scanValue, setScanValue] = useState('')
  const scanValueDebounced = useDebounce(scanValue, 300)

  useEffect(() => {
    setChips([...chips, scanValueDebounced])
    // reset scanValue, should reflect in MuiChipsInput
  }, [scanValueDebounced])

  function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
    e.preventDefault()
    // ...
  }

  return (
    <form onSubmit={handleSubmit}>
      <MuiChipsInput value={chips} onInputChange={(v) => setScanValue(v)} />
      <Button>submit</Button>
    </form>
  )
}
@viclafouch
Copy link
Owner

Hey @Elfayer !

Fixed in 1.3.1 : https://github.com/viclafouch/mui-chips-input/releases/tag/v1.3.1

Ty 😘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants