react-bootstrap-typeahead icon indicating copy to clipboard operation
react-bootstrap-typeahead copied to clipboard

Allow dropdown to stay open when multi-selecting

Open ryanlynnhorlacher opened this issue 8 years ago • 5 comments

When multi-selecting, it would be nice if the dropdown menu stayed open after a selection to allow the user to continue selecting.

ryanlynnhorlacher avatar Jan 31 '18 00:01 ryanlynnhorlacher

Note that you can do this yourself:

<Typeahead
  multiple
  onChange={(selected) => {
    this._typeahead.getInstance().focus();
  }}
  options={[...]}
  ref={typeahead => this._typeahead = typeahead}
/>

ericgio avatar Jan 31 '18 18:01 ericgio

Thanks for the quick response! This is a great component. Thank you for making and maintaining it.

ryanlynnhorlacher avatar Jan 31 '18 20:01 ryanlynnhorlacher

TLDR; Old solution didn't work, I had to use toggleMenu.

i.e.

const ref = React.useRef()
const [selected, setSelected] = React.useState([])

return (
  <Typeahead
    multiple
    id="keep-menu-open"
    onChange={(selections) => {
      setSelected(selections)
      ref.current.toggleMenu()
    }}
    options={options}
    placeholder="Choose a state..."
    ref={ref}
    selected={selected}
  />
)

nickgrealy avatar Nov 05 '21 05:11 nickgrealy

@nickgrealy great example, thank you! Here's a working sandbox link for anyone else coming across this issue:

https://codesandbox.io/s/rbt-keep-menu-open-during-multi-select-nr2y4

ericgio avatar Nov 05 '21 08:11 ericgio

Select multiple options and reuse the search filtering and keep the menu open prevent control to scrolls back to top after selecting an entry

here is the working example

or u can refer the linked comment

NomanChali avatar Oct 20 '26 11:10 NomanChali