srigar / multiselect-react-dropdown

React multiselect dropdown with search and various options
https://10xn41w767.codesandbox.io/
MIT License
200 stars 114 forks source link

Unselect values without clicking on close icon #43

Closed ghassenchaar96 closed 4 years ago

ghassenchaar96 commented 4 years ago

Hi, thank you for this helpful package. I'm using the multiselect-react-dropdown as a catalog filter, and I wanted to know if there is a way to unselect values, not by clicking on the close icon of the selected value, but by clicking on my own filter tag. Below is my example: I have selected the 'Auto' value from the dropdown options.

dropdown

I want to unselect it by clicking on my own filter tag:

dropdown1

Thank you !

srigar commented 4 years ago

@ghassenchaar96 In the below example, all selected values will be this.state.selectedValues and u can display any where. Also any changes in this.state.selectedValues will rerender multiselect component. For example, by removing any value from selectedValues will rerender the component

<Multiselect
options={this.state.options} // Options to display in the dropdown
selectedValues={this.state.selectedValue} // Preselected value to persist in dropdown
onSelect={this.onSelect} // Function will trigger on select event
onRemove={this.onRemove} // Function will trigger on remove event
displayValue="name" // Property name to display in the dropdown options
/>