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

How to change MultiSelect value programatically? #6515

Closed
1 of 2 tasks
Jodebu opened this issue Jul 22, 2020 · 5 comments
Closed
1 of 2 tasks

How to change MultiSelect value programatically? #6515

Jodebu opened this issue Jul 22, 2020 · 5 comments

Comments

@Jodebu
Copy link

Jodebu commented Jul 22, 2020

What package(s) are you using?

  • carbon-components
  • carbon-components-react

Summary

We are using Carbon inputs in a filter form where we need to include a "reset filters" button, which sets the state of the form to the initial state. Every input gets initialiazed as expected except for MultiSelect.Filterable, which retains the selection (even though the state changes properly and the list is correctly unfiltered).
Since the MultiSelect does not have a traditional "value" prop, is there a way to programatically change or restart the selected items?

Relevant information

  • react: 16.13.1
  • carbon-components: 10.14.0
  • carbon-components-react: 7.14.0

Please do not hesitate to ask for any extra information you mey need.
Thank you very much in advance!

@emyarod
Copy link
Member

emyarod commented Jul 27, 2020

I don't believe this use case is well supported beyond setting the initial selected items and rerendering the component with modifiede initial selected items using a key

@nagiah
Copy link

nagiah commented Oct 9, 2020

I'm using Carbon MultiSelect in a filter form with a "reset filters" button. initialSelectedItems is not getting cleared when set to empty array [].
Could you please provide a working example on how to clear MultiSelect selected items programmatically?

@tw15egan
Copy link
Collaborator

tw15egan commented Oct 9, 2020

@nagiah can you put your code up in a CodeSandbox so we can take a look and see whats going wrong?

@nagiah
Copy link

nagiah commented Oct 10, 2020

Here's an example on sandbox:
https://codesandbox.io/s/modest-merkle-fzltr

@tw15egan
Copy link
Collaborator

Seems this is a dupe of #4812, so I'm going to close this issue so we can keep the conversation in one place.

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

No branches or pull requests

5 participants