Focus should remain on the label rather than forwarded to the labeled
element.
Co-Authored-By: Mu-An Chiou <[email protected]>
Differential D67676
Bug 1240285 - Forward focus only if label is not focusable r=edgar Authored by dgraham on Mar 20 2020, 5:53 PM. Tags None Referenced Files
Tokens
Details
Focus should remain on the label rather than forwarded to the labeled Co-Authored-By: Mu-An Chiou <[email protected]>
Diff Detail
Event TimelineComment Actions This patch seems to regress Testcase #3. The current behavior when clicking the button is to focus the target text field (in both Firefox and Chrome). With this patch, the button is focused and nothing happens after that. Comment Actions Looking at chromium code it seems we should still try to focus the control if the label is not focusable itself, or such: https://source.chromium.org/chromium/chromium/src/+/master:third_party/blink/renderer/core/html/forms/html_label_element.cc;l=234;drc=ee4cff87f02e46e1fbbdaef0aa123e05761b35e8. WebKit has similar code. So we should probably keep the override but do something like: {
nsIFrame* frame = GetPrimaryFrame(FlushType::Frames));
if (frame && frame->IsFocusable()) {
return nsGenericHTMLElement::Focus(aOptions, aCallerType, aError);
}
}
if (RefPtr<Element> elem = GetLabeledElement()) {
return elem->Focus(aOptions, aCallerType, aError);
}Or such. I pushed this to try on behalf of Mu-an. Hopefully there are some pre-existing tests that start failing with this change. https://treeherder.mozilla.org/#/jobs?repo=try&revision=7513d59996433b09d6a38e60bdcc8fa4b4e0ec3e Happy to help pushing an updated patch or so on. Comment Actions @emilio We applied your suggestion and added WPT tests for the expected focus forwarding behavior. The test for an empty tabindex attribute currently fails in Firefox and passes in Chrome. Can you push this branch again to Try? Thanks for your help! Comment Actions Thanks @edgar! That looks pretty good. The only thing that's making things orange and are not flaky is this test you're adding (the empty tabindex subtest). Per the discussion in matrix, it seems this is an expected failure and Firefox shouldn't consider empty tabindex as focusable. If so what needs to get done is to annotate this test as failing, pointing to a bug. This would be a matter of creating a file called testing/web-platform/meta/html/semantics/forms/the-label-element/forward-focus-to-associated-element.html.ini with something like this as contents: [forward-focus-to-associated-element.html]
[focusing a label with empty tabindex should forward focus to the labelable element]
expected: FAIL
bug: <link-to-relevant-bug>That should make the test pass locally when you do ./mach wpt testing/web-platform/tests/html/semantics/forms/the-label-element/forward-focus-to-associated-element.html (and also on automation). With that I think this should be good to land, though I suggested the implementation so @edgar should probably be the one to stamp it if it looks good to him :) Comment Actions We added the expected test failure file and the label tests pass locally. According to the HTML spec, invalid tabindex values—non-integer or empty—fall back to platform focus behavior, and labels are not focusable.
—https://html.spec.whatwg.org/#the-tabindex-attribute We found this report describing the tabindex focus issue: https://bugzilla.mozilla.org/show_bug.cgi?id=1128054. Thanks again for all of your help getting this branch merged. Comment Actions
Comment Actions Thank you! Removing mats from the reviewer list because his feedback was addressed. Do you have commit access? If not, you can add the "check-in needed" tag, and it'll get pushed for you, or I can push it too if you want. | |||||||||||||||||||||||||||||||||||||||||