Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Is there a way to limit number of selections? #62

Open
pankajsoni19 opened this issue Nov 16, 2019 · 1 comment
Open

Is there a way to limit number of selections? #62

pankajsoni19 opened this issue Nov 16, 2019 · 1 comment

Comments

@pankajsoni19
Copy link

No description provided.

@liamdiprose
Copy link

In your onSelectedChanged handler function, you can decide whether to update the state object or not:

const maxSelected = 3;
const { options, selected } = this.state;
<MultiSelect
      options={options}
      selected={selected}
      onSelectedChanged={(newSelected) => {
          if (newSelected.length <= maxSelected) {
              // Number of Selections is OK, save to state...
              this.setState({selected: newSelected})
          } else {
              console.log("Too many selected");
          }
       }}
   />

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

No branches or pull requests

2 participants