Skip to content

Ability to keep menu open during multi-select #375

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

Closed
damonmiller513 opened this issue Aug 31, 2018 · 4 comments
Closed

Ability to keep menu open during multi-select #375

damonmiller513 opened this issue Aug 31, 2018 · 4 comments

Comments

@damonmiller513
Copy link

Current Version: 3.2.2

Description of use:
We recently switched from react-select to react-bootstrap-typeahead which we like way better!!! However, after looking through all your docs there is still one feature that I have not been able to make work which existed in react-select - the ability to leave the menu open when selecting multiple options. This is extremely handy for multi-select boxes!

For reference, here is the information on the property from react-select: https://react-select.com/props
closeMenuOnSelect boolean = true
Close the select menu when the user selects an option

Feature Request:
Add a boolean property on whether to close the menu upon selection, defaulting to true like it currently behaves.

@ericgio ericgio changed the title Feature Request: property similar to closeMenuOnSelect=false Property similar to closeMenuOnSelect=false Sep 1, 2018
@ericgio ericgio changed the title Property similar to closeMenuOnSelect=false Ability to keep menu open during multi-select Sep 1, 2018
@ericgio
Copy link
Owner

ericgio commented Sep 1, 2018

Hey @Damonmiller, thanks for the kind words :) Note that what you're asking for is possible by doing the following:

<Typeahead
  multiple
  onChange={(selected) => {
    // Retain focus to keep the menu open when making new selections.
    if (selected.length === this.state.selected.length + 1) {
      this._typeahead.getInstance().blur();
      this._typeahead.getInstance().focus();
    }
    this.setState({selected});
  }}
  options={[ ... ]}
  ref={(typeahead) => this._typeahead = typeahead}
  selected={this.state.selected}
/>

It's a little hacky because the input retains focus when an item is selected, so you need to blur and re-focus the input to re-open the menu. It should give you the behavior you want though. As far as adding this as a feature, I'll consider it, though my general philosophy has been to try and provide a flexible API that allows customization rather than simply add one-off props. If I did add a prop, it would probably be for controlling the menu (see #325) which would provide better control for the code above.

@damonmiller513
Copy link
Author

Thanks! This worked beautifully as a workaround!

@ericgio
Copy link
Owner

ericgio commented Jan 24, 2019

open and defaultOpen props were added in v3.3.0

@ericgio ericgio closed this as completed Jan 24, 2019
@nickgrealy
Copy link

Not sure if this is right, but i used toggleMenu.

if (selected.length > 0) ref.current.toggleMenu(true)

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

3 participants