| Summary: | Clicking button drops focus entirely | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Andy Blum <andy.blum.01> |
| Component: | Forms | Assignee: | Nobody <webkit-unassigned> |
| Status: | NEW --- | ||
| Severity: | Normal | CC: | akeerthi, a_protyasha, ap, bcronin, cdumez, cyb.ai.815, darin, emilio, jcraig, kevin_neal, matt, m.goleb+bugzilla, mike, rego, rniwa, webkit-bug-importer, webkit, webkit, wenson_hsieh |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Safari 14 | ||
| Hardware: | Mac (Apple Silicon) | ||
| OS: | macOS 11 | ||
|
Description
Andy Blum
2021-09-03 14:05:36 PDT
It’s possible that this behavior was required to make websites work--may require some research to find out. But pulling focus away when you push a button, something that does not happen on Mac outside web browsers, dilutes the value of macOS WebKit sticking with focus behavior that matches the rest of the Mac platform. Would be good to fix this. Or we may find that as requested in bug 22261 we should just go full-Windows-style-focus even on Mac as many other browsers did. Regarding this topic, and as part of the discussion around :focus-visible and WebKit [*], there was an idea to give web authors the possibility to mark an element as non-focusable (in order to mimic Mac's behavior): > For authors who want a control that participates in the tab focus cycle, but without drawing a focus ring on tap or click, [a better solution may be] to give them a way to make elements keyboard-focusable but not mouse-focusable. I don’t think there’s any support in the web platform for that, although the opposite is possible with tabindex="-1". [*] https://github.com/WICG/focus-visible/issues/257#issue-894585219 Cross linking this to https://www.drupal.org/project/drupal/issues/3269716 (this issue is the root of that issue) If anyone stumbles across this issue because you've got a situation where focusout on button click is triggering some javascript, you can use tabindex to catch the "dropped" focus. Codepen: https://codepen.io/andy-blum/full/PoEzOwB This is kind of duplicate of bug #112968. ^ It's true that this is a duplicate of https://bugs.webkit.org/show_bug.cgi?id=112968 in that the underlying issue appears to be the same. But it seems that that issue mostly considers the implications for visual focus indicators, which is not the only symptom of the underlying issue (as noted here, the issue is also problematic for anyone trying to monitor focus as a means of controlling UI). Tangentially, one thing that's interesting (to me, at least) is that the loss of focus that comes from clicking on a button does NOT necessarily cause the Selection to be lost in `contenteditable` nodes the way focus transitions usually do in WebKit (but shouldn't; see https://bugs.webkit.org/show_bug.cgi?id=224570). It's not that it drops focus entirely, but it focuses it the nearest focusable ancestor, which is actually even worse. If you have a `<main tabindex="-1">` for example that is focused as you navigate your SPA, `<main>` will receive focus from the button elements. Otherwise it falls back to `<body>`. Here's a simple example: https://codepen.io/stowball/pen/gOrMowN This bug also affects non-keyboard-focusing <input> types like checkboxes. Safari 17.2.1 (Mac) allows a partial workaround: If `tabindex` is explicitly set on the element being clicked, focus is not pulled away. I think this is the same fix mentioned in bug 112968, comment 12. This is natural enough for buttons, but anything with a <label> requires adding `tabindex` to the <label> as well, which is odd at best. |