moroshko / react-autosuggest

WAI-ARIA compliant React autosuggest component
http://react-autosuggest.js.org
MIT License
5.97k stars 587 forks source link

Force open suggestions on focus (even without suggestions) #334

Open Razinsky opened 7 years ago

Razinsky commented 7 years ago

In my app, I use renderSuggestionsContainer to add some custom action buttons right after the suggestions. I need those actions to be available from the moment the user focus on the input, even before typing anything. Is there a proper way of achieving this?

Thanks.

moroshko commented 7 years ago

Interesting scenario!

I can't see an easy way to achieve this with the current API. Here is an attempt to achieve something that looks similar.

If you have any ideas how to extend the API to support this scenario, please share.

alex-shamshurin commented 7 years ago

autosuggest-arrow

We have the same options to open autosuggest on outside event (clicking on arrow)

    if (!this.autosuggest.state.isCollapsed) {
      console.log('Before close onClick')
      this.autosuggest.setState({ isCollapsed: true })
    } else {
      console.log('Before open onClick')
      this.autosuggest.setState({ isCollapsed: false })
    }

But this scenario does not work. It will open suggestions only when click event is originated from autosuggest's input field.

I think we really need this.autosuggest.open() and this.autosuggest.close() methods.

alex-shamshurin commented 6 years ago

It's also might be a trigger mode when suggestion list should be opened on click(touch) event and closed on next click, working like a trigger. No matter whether empty input or not.