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

Auto-selecting the first suggestion

Open thienanle opened this issue 8 years ago • 9 comments

Is this currently possible? I think it would help in terms of UX. Type, enter, type, enter. Rather than type, down, enter, type, down, enter.

thienanle avatar Nov 01 '16 00:11 thienanle

I suppose it depends on whether the allowNew flag is set, perhaps when this is false (only suggested tags may be picked) that would make sense?

i-like-robots avatar Nov 28 '16 12:11 i-like-robots

Hi @i-like-robots

its doesn't as you say, i see the code always set selectedIndex = -1

Can I push a change, I made it work ? since i wants first item to be auto selected so it will be easier for user to select incase of first item.

also there is fix required to work TAB key well, when minQueryLength = 0, this too.

muthukumarse avatar Apr 21 '17 06:04 muthukumarse

This is a good idea, whether allowNew is set or not, having the first suggestion automatically focused means you can just hit enter to select it, rather than clicking or having to press down to select it.

Billy- avatar Apr 25 '17 10:04 Billy-

added pull request, pl look at the changes. PR - auto-select-first-item

muthukumarse avatar May 01 '17 23:05 muthukumarse

Re-reading my comment and now realise why it wouldn't make sense if allowNew was true. I'd say enable this behaviour is allowNew is false but not if it's true.

Billy- avatar Feb 12 '19 10:02 Billy-

@i-like-robots any update on when this will be merged? 🙏

agamm avatar Nov 03 '19 16:11 agamm

We would love this option for our project as well, any news if it will make it into v6? We are using v6 beta 3 currently

bslinger avatar Jan 29 '20 00:01 bslinger

Currently searching for the same solution for the project we are working on atm. Would love to see some movement on this issue. :)

ghost avatar Feb 13 '20 13:02 ghost

For those wanting a workaround:

useEffect(() => {
     if (suggestions.length > 0) {
          // library doesn't auto-select the first item in the list
          inputRef.current.setState({  index: 0 });
     }
     else {
          // if no results, don't want to highlight
          inputRef.current.setState({ index: -1 });
     }
}, [suggestions]);

Where your inputRef is the ref to your element.

datzun avatar Aug 24 '20 19:08 datzun

This behaviour is available in v7+.

i-like-robots avatar Oct 23 '23 08:10 i-like-robots