React-autosuggest: Force dropdown to open

Created on 22 Apr 2016  路  10Comments  路  Source: moroshko/react-autosuggest

Hey!

Is there a way I can force the drowdown to open with the latest suggestions filled, without having to focus on the input?

My idea is to set the focus on the callback of another event...

Thanks!

Most helpful comment

YES!! Thanks. You rock!
Maybe an idea to expose a method on the control to do this? Or something like this?

All 10 comments

Yeah, setting the focus programatically should do the trick.

I see, I'll do some tests then...

I'll tell you later if I succeeded :)

Thanks

worked like a charm! thanks @moroshko

Maybe a silly question but how can I achieve this? I use the component as a combobox with a tiny arrows button superimposed on the component. I want to toggle the suggestions panel when the user clicks this button (similar to a select element). I'm not sure how to achieve this.

@dannybloe To be honest it's been a while since I've done it, and I'm not 100% sure the answer I'll give you is the correct one... But the idea is set a ref in the AutoSuggest component, and get the input DOM reference and triggering .focus() on it

<AutoSuggest ref="suggest" />


this.refs.suggest.getElementsByTagName('input')[0].focus()

That might do the trick

@dannybloe Something like this?

Ah, almost. I'd like the button to behave as a toggle: when it is expanded, it should collapse and vice-versa. I can't find a way to close the suggestions container.

@dannybloe Does this help?

YES!! Thanks. You rock!
Maybe an idea to expose a method on the control to do this? Or something like this?

I'll think about this.

Was this page helpful?
0 / 5 - 0 ratings