Enter key does not open menu while focused
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
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.
resolved in v2.4.0 and closed
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} />
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.
Is this issue back? My team is noticing it with react-select 5.2.2. Can we re-open it?
@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).
@lgoldb This was never an issue.
Enteris 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
onKeyDownprop (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/