Bug 236322
Summary: | Dialog's "previously focused element" and focus-visible | ||
---|---|---|---|
Product: | WebKit | Reporter: | Darin Senneff <darin.senneff> |
Component: | DOM | Assignee: | Nobody <webkit-unassigned> |
Status: | NEW | ||
Severity: | Normal | CC: | koivisto, ntim, rego, webkit-bug-importer |
Priority: | P2 | Keywords: | InRadar |
Version: | Safari Technology Preview | ||
Hardware: | Mac (Intel) | ||
OS: | macOS 12 | ||
Bug Depends on: | |||
Bug Blocks: | 84635 |
Darin Senneff
When closing a <dialog> element, focus is only moved back to the "previously focused element" if a keyboard was used to initially show the dialog. I'm assuming this has to do with the focus-visible algorithm, as a click doesn't normally put visible focus on a button.
But because the <dialog> autofocuses a button upon being opened, it's possible users will then use the keyboard to close the modal rather than click – by pressing the ENTER, SPACE, or ESC keys. In these cases where the user has changed their input method from click/tap to keyboard, should the previous element now receive focus?
I think regardless of the input method used to close a modal, focus should be placed on the previous element to help re-orient the user. But at minimum I think it should in cases where a keyboard was used to close the <dialog>.
Looking at the spec's dialog focusing steps, this edge case seems beyond that. But think there's value in it.
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Manuel Rego Casasnovas
Hi, thanks for the bug report.
If you're testing this on Mac, <button> are not mouse focusable on Mac (see https://bugs.webkit.org/show_bug.cgi?id=229895 for more details).
So I guess that when you close the dialog, if it was opened by a button, it's not going to be focused when you close it.
I've tested on WebKitGTK (Linux), and the button that opens the dialog gets focused when I close it.
If the problem is unrelated to the buttons not being click focusable on Mac, could you please create a test case reproducing the issue?
Darin Senneff
Yup, I get the non-focusable button if the <dialog> is opened and closed with a mouse. And that if its opened and closed with a keyboard that the button does get focus.
But what if the <dialog> is opened with a mouse but closed with a keyboard? Since the element autofocuses a button upon opening (and can be closed with the ESC key), it's likely that some users will switch to a keyboard after originally opening the <dialog> with their mouse/finger. In those cases, doesn't it make sense to put keyboard focus to the button?
Radar WebKit Bug Importer
<rdar://problem/88969727>