Internal state of Chip can't be reset
I'm submitting a ...
[x] bug report
Current behavior
Currently, it is not possible to reset the state of a Chip entirely. This sandbox shows how the bug can be reproduced.
https://codesandbox.io/s/724l4x5mqj
Expected behavior I want to have some way to reset the internal state of the Chip, so I can remove the 'foo'-part (as shown in the sandbox).
Minimal reproduction of the problem with instructions https://codesandbox.io/s/724l4x5mqj
Please tell us about your environment:
-
React version: React version:
16.8.6 -
PrimeReact version: PrimeReact version:
3.1.2 -
Browser: Chrome: 73.0.3683.103 (Officiële build) (64-bits)
-
Language: [all | TypeScript X.X | ES6/7 | ES5] TypeScript: 3.4.3
Hi, I don't think it's a bug but an RFC.
this.setState({ items: ["hello"] }); should not remove your 'foo' text, that would imho be unexpected behaviour. You adjust the array of Chips and something else will disappear.
There is indeed no prop for the input:text box. as far as I can see so that one would be nice I guess.
For now you might be able to reach it through the ref attribute ( untested )
Accessing the input element with the ref-attribute works! The onReset-function then becomes like this, which works fine for me.
onReset = () => {
this.setState({ items: ["hello"] });
this.ref.current.inputElement.value = '';
};
Thanks for this quick answer!