Dropdown fires onChange when navigating through the options with keyboard cursor (UP and DOWN) instead of when you actually select the desired option (RETURN)
See original GitHub issueBug Report
Steps
You need a Dropdown with search and selection enabled. Then…
- Click in the dropdown and make a search.
- Set an onChange function that just do
console.log('onChange executed'). - Click on the Dropdown to open the options.
- Press arrow keys up and down on the keyboard to start moving over the options.
- You’ll see that everytime you press the key, onChange is fired (you’ll see the console.log message)
With current behavior, if your application fires some code when you select an option (loading another dropdown, showing/hiding something, etc.), that code is going to be executed when you’re moving through the options. This can be problematic, because maybe you’re reseting some state, so you can´t recover that data.
Expected Result
onChange only should be fired when you actually select one option pressing ENTER.
Actual Result
onChange is fired when you move through the options just to find the one you want to select. So, onChange is executed even if you don’t change your selection.
Version
0.82.5
Testcase
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
126379 - Select (size=1) onChange not called using down ...
If the user drops the drop-down and selects an option then rolls it back up (all using the keyboard) then onchange should fire...
Read more ><select> change event not fired when using keyboard
The change event is fired when the element loses focus. Change the value with the keyboard and press tab, and the change event...
Read more >Keyboard: keydown and keyup - The Modern JavaScript Tutorial
So if we want to track any input into an <input> field, then keyboard events are not enough. There's another event named input...
Read more >Banner Basics and Navigation - Staff
Navigation in Banner is accomplished with the mouse, keyboard, ... Note: With the cursor in the Go to... field, use the Up and...
Read more >Dropdowns · Bootstrap v5.0
By default, the dropdown menu is closed when clicking inside or outside the dropdown menu. You can use the autoClose option to change...
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 Free
Top 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

@rigobauer This is the default behavior by design. You can get the behavior you are expecting by setting the
selectOnNavigationprop tofalse. https://react.semantic-ui.com/modules/dropdown/#usage-select-on-navigationClosing as this has been addressed.