From bdd3b56aaab391eb38e6e87fb091cf796670145d Mon Sep 17 00:00:00 2001 From: Joey Arhar Date: Mon, 17 Apr 2023 12:57:55 -0700 Subject: [PATCH 1/2] Only restore dialog focus if focus is in the dialog Fixes https://github.com/whatwg/html/issues/8904 This patch prevents the behavior where closing a dialog focuses the previously focused element from before the dialog was opened only if focus is in the dialog when the dialog closes. Without this, focus can unexpectedly shift away from an element which is not going away, like a text input that the user is currently typing into for example. --- source | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source b/source index 9e11deef691..62eb6a0d63a 100644 --- a/source +++ b/source @@ -60181,8 +60181,10 @@ interface HTMLDialogElement : HTMLElement {
  • Set subject's previously focused element to null.

  • -
  • Run the focusing steps for element; the viewport should not be - scrolled by doing this step.

  • +
  • If subject's node document's focused area of the + document's DOM anchor is a shadow-including inclusive + descendant of element, then run the focusing steps for + element; the viewport should not be scrolled by doing this step.

  • From 08c05b05b4270d5ac4fa47bd25ac3c942df666b9 Mon Sep 17 00:00:00 2001 From: Joey Arhar Date: Tue, 18 Apr 2023 13:01:47 -0700 Subject: [PATCH 2/2] always restore focus for modal dialogs --- source | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source b/source index 62eb6a0d63a..1a3f40bea69 100644 --- a/source +++ b/source @@ -60183,8 +60183,9 @@ interface HTMLDialogElement : HTMLElement {
  • If subject's node document's focused area of the document's DOM anchor is a shadow-including inclusive - descendant of element, then run the focusing steps for - element; the viewport should not be scrolled by doing this step.

  • + descendant of element, or subject's is modal is true, + then run the focusing steps for element; the viewport should not be + scrolled by doing this step.