user944513
user944513

Reputation: 12729

How to show select box on focus and close after select?

Could you please tell me how to show select box on focus of input field and close after select item from the drop down? Here is my code

return (
      <div className="App">
        <Select
          value={selectedOption}
          closeMenuOnSelect={false}
          menuIsOpen={menuIsOpen}
          isMulti={true}
          className="select-item"
          classNamePrefix="select-item"
          onInputChange={() => this.setState({ menuIsOpen: true })}
          onChange={this.handleSelectedChange}
          options={options}
        />
      </div>
    );

https://codesandbox.io/s/5v41wrxw9n

using this plugin https://github.com/JedWatson/react-select

Upvotes: 0

Views: 2532

Answers (1)

satwik
satwik

Reputation: 607

Refer to the link for updated code: https://codesandbox.io/s/mmjvp25z38

  1. I used onFocus to show dropdown
  2. Used on handleSelectedChange method and updated menuIsOpen prop via set state

Upvotes: 3

Related Questions