Dropdown: When clicking to close a dropdown, it fires "click" and "blur" events
See original GitHub issueThis issue happens when controlling manually (via states) the status of a dropdown.
Steps
If you click the “Not ok button” to close the drop-down you will notice that it triggers the click
and blur
events (It shouldn’t fire blur
cause I’m still inside the component).
Now, if you click the “ok button” repeatedly, you will notice that only the click
event is fired, regardless if the dropdown is opening or closing, and the blur
happens only when you actually click outside of the related button, as expected.
Expected Result
When clicking the “not ok button” to close a drop-down, it should fire only a click
event.
Actual Result
When clicking the “not ok button” to close a drop-down, it fires a click
and blur
event.
Version
0.78.3 OS: High Sierra
Testcase
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Need to fire an event when a select menu closes or hides ...
I have the following dropdown select menu. I am able to fire event onChange or onBlur. But I want to be able to...
Read more >X-On
In the above example, after showing the dropdown contents by clicking the "Toggle" button, you can close the dropdown by clicking anywhere on...
Read more >Element: blur event - Web APIs | MDN
The blur event fires when an element has lost focus. The event does not bubble, but the related focusout event that follows does...
Read more >onblur Event
The onblur event occurs when an element loses focus. The onblur event is often used on input fields. The onblur event is often...
Read more >Events - Action Commands
Firing the focus or click event on the input form field may cause the drop-down box to open, but the blur event may...
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
I deleted
from Dropdown.js and it fires only the click event. Also, #627 seems to be unaffected. I’ll write some tests and issue a pull request
Thanks for the report and test case. Here’s our problem in Dropdown.js, the close handler is explicitly calling blur
I believe the culprit is #627 (see inline comments in code above). Rather than blurring the Dropdown to prevent the issue noted, it seems we should be detecting when the browser tab is switched back and not reopen.
I’d investigate which methods are being called when the browser tab is switched away and back. That process needs to not re-open the Dropdown AND we should retain its focus.