.focus() in onkeydown handler causes a click event on a link when pressing the Enter key
Categories
(Core :: DOM: Events, defect, P3)
Tracking
()
People
(Reporter: wizard04, Unassigned, NeedInfo)
Details
Attachments
(1 file)
1.55 KB,
text/html
|
Details |
![]() |
||
Comment 1•10 years ago
|
||
Reporter | ||
Comment 2•10 years ago
|
||
Comment 3•8 years ago
|
||
Comment 4•8 years ago
|
||
Comment 5•8 years ago
|
||
Comment 6•8 years ago
|
||
Updated•7 years ago
|
Comment 7•6 years ago
|
||
Same issue here but with the "Space" key, "Enter" is fine.
Quite problematic when implementing a11y keyboard navigation for components like menu buttons.
https://www.w3.org/TR/wai-aria-practices-1.1/examples/menu-button/menu-button-actions.html
User Agent: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0"
Comment 8•5 years ago
|
||
Another example with "Space" key causing this problem on GitHub, where we implement the ARIA menu pattern via <details-menu>
(similar to https://bugzilla.mozilla.org/show_bug.cgi?id=1220143#c7)
Steps:
- Go to https://github.github.io/details-menu-element/examples/,
- Tab to the first menu button, press "Enter" to open it,
- Tab to the first menu item, press "Space" to select it,
- Observe that menu is closed but immediately opened again.
This can be further verified by registering a click event listener on <summary>
. It does not happen on Chrome nor Safari.
On github.com, you can see this happening in the dropdown menus on the right side header for both the + icon menu, and the personal menu.
Here's a GIF showing this behavior on GitHub menu: https://cl.ly/114b7b4ec86b/Screen%20Recording%202020-03-20%20at%2015.48.gif
UA: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:74.0) Gecko/20100101 Firefox/74.0
Comment 9•5 years ago
|
||
Here's a reduced test case: https://html-is.glitch.me/firefox-space-focus.html
Comment 10•5 years ago
|
||
I've submitted a WPT for the space trigger issue: https://github.com/web-platform-tests/wpt/pull/22424
Comment 11•5 years ago
|
||
We create the click event based on keypress with enter and keyup with space here: https://searchfox.org/mozilla-central/rev/06985b12a4abe393c02c6bf14d86bf3d25c33337/dom/html/HTMLButtonElement.cpp#235-244.
Somehow we need to suppress this click event if the initial keydown event was on a different element. We actually have PresShell::EventHandler::sLastKeyDownEventTargetElement;
(source) already so maybe we could do this? Masayuki seems to have added this, so needinfo-ing them.
Comment 12•5 years ago
•
|
||
I don't understand the logic for now. keypress
event should be fired on any browsers for Space
and Enter
key press. So, keypress
event should be tested in the WPT. Do you think which one of the following is expected behavior?
option: 1
keypress
event should be fired on previously focused element.click
event should be fired as the default action if the previously focused element's normal behavior is so.
option: 2
keypress
event should be fired on newly focused element.- But it's default action shouldn't be performed by the
keypress
event.
option: 3
keypress
event should be fired on previously focused element.- But it's default action shouldn't be preformed due to blurred.
If the last one, I have another question. If the keypress
event listener takes back focus to the event target (previously focused element), the element should perform default action?
Anyway, I'm feeling odd to the WPT's expectation because nobody prevents its default.
Comment 13•5 years ago
|
||
keypress
event should be fired on any browsers for Space and Enter key press. So,keypress
event should be tested in the WPT.
That wouldn't give us the test failure though. Both Chrome and Safari have keypress fired on the newly focused button, but neither triggered click, which means option 2. As far as I can see, the previously focused element wasn't clicked in any browser despite nobody prevented default.
Comment 14•4 years ago
|
||
According to wpt.fyi, this has been fixed in https://wpt.fyi/results/uievents/order-of-events/focus-events/focus-management-expectations.html?label=master&label=stable&product=firefox-91.0&aligned&q=focus%20events! :tada:
Updated•3 years ago
|
Description
•