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

Enter key does not open menu while focused

Open GonchuB opened this issue 7 years ago • 7 comments

The menu is not opened when ENTER key is pressed and the menu is closed. From the source (onKeyDown), it looks like the first option should be focused, but nothing happens

Steps to reproduce

  • Go to https://codesandbox.io/s/00oykp18k0
  • Click the Select
  • Select "Chocolate"
  • With focus still on the Select, press Enter key

Expected result

  • Menu gets opened

Actual result

  • Nothing happens

GonchuB avatar Feb 07 '19 15:02 GonchuB

This is definitely not intended, focusOption should not be called on ENTER if the menu is not open. Fix for this will be released in v2.4.0 as part of https://github.com/JedWatson/react-select/pull/3427.

gwyneplaine avatar Feb 15 '19 04:02 gwyneplaine

resolved in v2.4.0 and closed

gwyneplaine avatar Feb 15 '19 05:02 gwyneplaine

This is my workaround:

Example Link: https://codesandbox.io/s/boring-pike-v9ohq?fontsize=14&hidenavigation=1&theme=dark

onKeyDown = (event) => {switch (event.key) { case 'Enter': if (!this.state.isOpen) { this.selectRef.setState({ menuIsOpen: true, }); break; } } };

<Select ref={el => (this.selectRef = el)} onKeyDown={this.onKeyDown} />

Veena624 avatar Feb 24 '20 10:02 Veena624

I guess this issue is back? At least for me if a Dropdown is focused (ether through tab or through a form label for connected to the input) the menu does not open when pressing enter.

fkrauthan avatar Dec 02 '21 01:12 fkrauthan

Is this issue back? My team is noticing it with react-select 5.2.2. Can we re-open it?

lgoldb avatar Jun 19 '23 21:06 lgoldb

@lgoldb This was never an issue. Enter is not meant to open the dropdown, only to select an option if the dropdown has been opened.

But you can implement this behaviour by yourself using the onKeyDown prop (see https://github.com/JedWatson/react-select/issues/3414#issuecomment-590264726 for possible implementation).

Rall3n avatar Jun 20 '23 08:06 Rall3n

@lgoldb This was never an issue. Enter is not meant to open the dropdown, only to select an option if the dropdown has been opened.

But you can implement this behaviour by yourself using the onKeyDown prop (see #3414 (comment) for possible implementation).

For reference, this might need to be reconsidered. Our third party accessibility audit is requesting that the dropdown be expanded on both spacebar and enter pressed on focus. They referenced the following W3 documentation: https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-select-only/

IanBoyte avatar Oct 18 '24 19:10 IanBoyte