Bug 112968

Summary: FKA: mouse click on buttons causes focus (document.activeElement) to be lost
Product: WebKit Reporter: James Craig <jcraig>
Component: AccessibilityAssignee: Nobody <webkit-unassigned>
Status: RESOLVED CONFIGURATION CHANGED    
Severity: Normal CC: cfleizach, fotis.papadogeorgopoulos, gsnedders, jcraig, me, ntim, rego, webkit-bug-importer, webkit
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=22261
Attachments:
Description Flags
test case demonstrating bug none

Description James Craig 2013-03-21 14:44:22 PDT
REPRO *
1. Load attached test case.
2. Tab so that focus is on one of the buttons.
3. Perform a mouse click on the same button. (Notice focus ring disappears.)
4. Press Tab again. (focus has been lost and resets to the beginning of the document)

Note: It's probably okay to "hide" the focus pseudo-state when switching to a mouse, but Tabbing should cause focus to come back to the same element rather than losing document.activeElement entirely.
Comment 1 James Craig 2013-03-21 14:47:19 PDT
Created attachment 194349 [details]
test case demonstrating bug
Comment 2 Radar WebKit Bug Importer 2013-03-21 14:48:14 PDT
<rdar://problem/13477257>
Comment 3 James Craig 2013-03-21 14:48:42 PDT
See expected behavior in Firefox 19 for Mac.
Comment 4 Radar WebKit Bug Importer 2013-03-21 14:49:02 PDT
<rdar://problem/13477269>
Comment 5 Alexey Proskuryakov 2013-03-22 15:51:21 PDT
See also: bug 22261.
Comment 6 James Craig 2015-03-11 23:20:37 PDT
<rdar://problem/13477257>
Comment 7 Mu-An Chiou 2018-08-09 11:26:44 PDT
Any updates on this? I see that there's not been any changes since the bug was reported 5 years ago. This issue makes building custom widget with focus management very tricky.
Comment 8 James Craig 2021-06-14 12:08:19 PDT
Relating to the newer :focus-visible tracker in bug 225148
Comment 9 Manuel Rego Casasnovas 2022-04-06 00:36:16 PDT
Very related bug, see bug #229895.
Comment 10 Mu-An Chiou 2023-09-12 03:43:27 PDT
Just talked about this at TPAC with ntim and jcraig I just want to add to the repro steps:

REPRO *
1. Load attached test case.
2. Tab so that focus is on one of the buttons.
3. Perform a mouse click on the same button. (Notice focus ring disappears.)
4. Press Tab again. (focus has been lost and resets to the beginning of the document)

As of 16.6, step 4 is no longer the case. the next focus point does land on the button. However if you do `setInterval(() => console.log(document.activeElement), 1000)` to observe the current focused element, you would see that after step 3, the activeElement goes back to body.

nTim mentioned that there has been a recent fix to account for how button[tabindex=0] should be click-focusable like div[tabindex=0]. https://github.com/WebKit/WebKit/pull/12743

Now that :focus-visible is implemented, I wonder if WebKit would mind reconsidering this special treatment (https://github.com/WebKit/WebKit/blob/b38121da42a0483fdb1bc13782f1c7a8059de100/Source/WebCore/html/HTMLFormControlElement.cpp#L255C13-L255C13) to buttons?
Comment 11 James Craig 2023-11-07 18:24:47 PST
Seems reasonable to me... When I filed this back in 2013, :focus-visible didn't exist so there wasn't a way to make this work for all use cases, but I think that wwide support of :focus-visible now unblocks this, right?
Comment 12 James Craig 2023-11-07 20:09:42 PST
Seems fixed in latest STP so this was probably resolved along with :focus-visible. Muan, if you know of other instances where this doesn't work, will you open a new issue?