Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: baf4a9a7ec0b8436f3dec8cb8c4b418f0795a308
https://github.com/WebKit/WebKit/commit/baf4a9a7ec0b8436f3dec8cb8c4b418f0795a308
Author: Ahmad Saleem <[email protected]>
Date: 2026-08-21 (Fri, 21 Aug 2026)
Changed paths:
M
LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-closedby-corner-cases-expected.txt
M
LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-focus-previous-outside-expected.txt
M Source/WebCore/html/HTMLDialogElement.cpp
Log Message:
-----------
dialog close() restores focus unconditionally instead of only when focus is
inside the dialog or it was modal
https://bugs.webkit.org/show_bug.cgi?id=322310
rdar://185549474
Reviewed by Tim Nguyen.
The close the dialog steps gate the focus restore [1]:
If subject's node document's focused area of the document's DOM anchor is a
shadow-including inclusive descendant of subject, or wasModal is true, then
run the focusing steps for element; the viewport should not be scrolled by
doing this step.
We ran that unconditionally, so closing a non-modal dialog yanked focus back
even when the author had moved it elsewhere. The stray focus change is
observable: it fires focusin, letting a listener re-enter the dialog's own state
machine. Capture wasModal after removing the open attribute, matching the spec's
step order, and gate on it.
The check uses the composed tree, not the shadow-including tree: a node slotted
into a dialog inside a shadow root is not a shadow-including descendant, yet
focus restore is expected for it. See whatwg/html#8904 [2], cited by
dialog-focus-previous-outside.html for that case.
This removes the FIXME from 319173@main and fixes the bug by handling focus
properly.
[1]
https://html.spec.whatwg.org/multipage/interactive-elements.html#close-the-dialog
[2] https://github.com/whatwg/html/issues/8904
*
LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-closedby-corner-cases-expected.txt:
Progression
*
LayoutTests/imported/w3c/web-platform-tests/html/semantics/interactive-elements/the-dialog-element/dialog-focus-previous-outside-expected.txt:
Ditto
* Source/WebCore/html/HTMLDialogElement.cpp:
(WebCore::HTMLDialogElement::close):
Canonical link: https://commits.webkit.org/319640@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications