question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

Bug Report

Steps

You need a Dropdown with search and selection enabled. Then…

  1. Click in the dropdown and make a search.
  2. Set an onChange function that just do console.log('onChange executed').
  3. Click on the Dropdown to open the options.
  4. Press arrow keys up and down on the keyboard to start moving over the options.
  5. 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

https://codesandbox.io/s/jn76nn5z5v

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
quiquegcommented, Mar 4, 2019

@rigobauer This is the default behavior by design. You can get the behavior you are expecting by setting the selectOnNavigation prop to false. https://react.semantic-ui.com/modules/dropdown/#usage-select-on-navigation

0reactions
brianespinosacommented, Jul 29, 2020

@rigobauer This is the default behavior by design. You can get the behavior you are expecting by setting the selectOnNavigation prop to false. https://react.semantic-ui.com/modules/dropdown/#usage-select-on-navigation

Closing as this has been addressed.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found