react-autosuggest icon indicating copy to clipboard operation
react-autosuggest copied to clipboard

Keep suggestions open after a choice is made

Open jonahgreenthal opened this issue 5 years ago • 5 comments

Is there a way to keep the suggestions open after a choice is made? Or, more generally: I want the suggestions to be open any time the input has focus.

I tried shouldRenderSuggestions={() => true}. It doesn't accomplish this.

jonahgreenthal avatar Jun 19 '19 20:06 jonahgreenthal

I have a similar case here, which is to suggest a table name with field name. So after user select a suggested table name, the suggestions then keep open to show the suggested fields inside the table. But the fact is that after click on a suggestion, it then close the suggestions list. No way to pop it again programmatically.

zxsure avatar Aug 06 '19 02:08 zxsure

@jonahgreenthal have you tried https://github.com/moroshko/react-autosuggest#alwaysrendersuggestions-optional

gilad-solter avatar Aug 06 '19 14:08 gilad-solter

@gilad-solter Unfortunately, simply using alwaysRenderSuggestions does not solve the specific issue being described. The issue is that when focusInputOnSuggestionClick is used (so that the focus is maintained), shouldRenderSuggestions does not continue to render suggestions after a choice is made even though it should (according to its described behavior).

benefacto avatar Sep 10 '19 19:09 benefacto

I agree, this is an issue. Seems to be a bug. I am looking for a work around.

khrome83 avatar Feb 11 '21 15:02 khrome83

Not sure if this is a perfect workaround for what you need, but it works for my use case:

const inputProps = {
    onClick: (e) => {
        e.currentTarget.blur();
        e.currentTarget.focus();
    },
};

...

<Autosuggest
    inputProps={inputProps} 
    shouldRenderSuggestions={() => true}
/>

This blurs and refocuses the input when it's clicked, which in turn triggers the suggestions to pop up again (much like the way react-autocomplete works).

globalmatt avatar Jun 05 '21 10:06 globalmatt