primereact icon indicating copy to clipboard operation
primereact copied to clipboard

Internal state of Chip can't be reset

Open NielsB95 opened this issue 7 years ago • 2 comments

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

NielsB95 avatar Apr 26 '19 11:04 NielsB95

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 )

rogiermulders avatar Apr 27 '19 14:04 rogiermulders

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!

NielsB95 avatar Apr 27 '19 18:04 NielsB95