bug(MatSelect): When navigating with keyboard, sometimes the first press of the down arrow is "ignored"
See original GitHub issueReproduction
The value of the first MatOption
in a MatSelect
must be null
. Example:
<mat-select>
<mat-option>--</mat-option> // <------- Here
<mat-option value="canine">Dog</mat-option>
<mat-option value="feline">Cat</mat-option>
</mat-select>
Steps to reproduce:
- Refresh development server
- Tab to the
MatSelect
- Use the down arrow to make a selection
- Notice that the very first press appears to be ignored
Expected Behavior
The first press of the arrow should select Dog
.
Actual Behavior
The first press of the arrow appears to do nothing.
Environment
- Angular: 11.0.6
- CDK/Material: 11.0.3
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): Windows
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Mat-select won't arrow navigate when auto-opened after ...
I have a mat-select located in a modal. Currently I have it setup so that after opening the modal, it will run open()...
Read more >Fix Arrow keys are not working in Windows 11/10 laptop ...
At times, the Arrow keys might not be working in Windows 11 or Windows 10 PC. If this problem is appearing on your...
Read more >OPERATION MANUAL - Dakota Ultrasonics
3) Press the UP and DOWN arrow keys to toggle the coating option on/off. 4) Wipe all couplant from the transducer face and...
Read more >OPERATION MANUAL - Global Test Supply
flaw detector portion of the DFX-7, use the UP/DOWN arrow keys to select “flaw detector”, followed by pressing the OK key start the...
Read more >The Dangers of Stopping Event Propagation - CSS-Tricks
This bug happens because the Bootstrap code responsible for closing the dropdown menu is listening for click events on the document.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The desired behavior for this is probably what the
matNativeControl
select element does. However, it seems silly to need to use a native select element to get this common behavior.Is there a workaround for this bug? When I create the selection values and put the first option as “Not Selected” with null as value in the selection list then the selected value is in fact exactly this value. But nevertheless it needs two arrow down presses to select the first option after this. I understand that the control uses null to reset the internal selection, but i think, if the selected value is an element that has the value null, it should be treated as if exactly this option was selected.
This option must be added to have the possibility to reset the select control with keyboard or mouse when there was an option selected before. When this option with the null value is missing from the select options then there is no way to set the control to “nothing selected”.
Will this issue be addressed in the near future or do we have to implement a workaround by ourselfes like adding a reset button to the selectbox and removing the null-entry from the option list?
A little sitenote to this bug: With this bug the behavior of this control is incosistent, when using the arrow keys to scroll through the available options. When first entering the control it needs two arrow downs to select the first visible option. But when going further down and up to the null option again it only needs one arrow down to select the first visible option again. So selecting null doesn’t really reset the control in the ui. This is a valid option there. It only resets the internal control, but without the possibility for the programmer to detect this fact. I don’t see a difference in the formcontrol in typescript code when the first option is selected or when the control is in the state where two key downs are needed to get to the first visible option.
Another site note: this bug doesn’t occur, when the null-option is not the first in the list. If this option is at the end of the select options then everything works fine. Also this bug doesn’t occur, when you select something, leave the field, go back to the field, select the null-value, leave the field and go back to the field. In this case one arrow key down is enough to select the first visible option. The possibility to set the control in this state when it is created would solve this issue.