Skip to content
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

How to close options dropdown? #129

Open
yantakus opened this issue Sep 11, 2015 · 3 comments
Open

How to close options dropdown? #129

yantakus opened this issue Sep 11, 2015 · 3 comments
Labels

Comments

@yantakus
Copy link

I want to close options dropdown programmatically. How ca I achieve this? Smth like focus would be great.

@henrikra
Copy link

I would like to know this one too! :)

@mattboon
Copy link

Me too!

@vrunjeti
Copy link
Contributor

Copied and pasted from #169:

This is somewhat of a workaround, but I managed to accomplish this with something like this:

constructor(props) {
  super(props)
  this.state = { hideDropdown: false }
  // bind functions listed below
}

closeDropdown() {
  this.setState({ hideDropdown: true })
}

showDropdown() {
  this.setState({ hideDropdown: false })
}

render() {
  const yourOptions = [ ... ]
  return (
    <Typeahead
      options={this.state.hideDropdown ? [] : yourOptions}
      onBlur={this.closeDropdown}
      onFocus={this.showDropdown}
    />
  )
}

Essentially, this makes use of how the selector won't render if there are no options by setting your options to an empty array when the input is blurred. So I guess it's a workaround since it doesn't directly close the dropdown, but puts it in a state to not show up at all.

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

No branches or pull requests

5 participants