From 9e71dbc2888d266d401bc7bc2d8f3924b1679a5f Mon Sep 17 00:00:00 2001 From: Sean Feng Date: Thu, 25 Mar 2021 14:38:36 -0400 Subject: [PATCH 1/5] Move the focus to the previously focused element for dialog.close() Add a new `previously focused` element to dialog as a pointer to the current focused element when `dialog.showModal()` and `dialog.show()` are called, such that `dialog.close()` can use it to restore the focus. See https://github.com/whatwg/html/issues/5678 for more details. --- source | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/source b/source index 1e94d53598a..ba943e3f28f 100644 --- a/source +++ b/source @@ -57498,6 +57498,8 @@ interface HTMLDialogElement : HTMLElement {
  • Add an open attribute to the dialog element, whose value is the empty string.

  • +
  • Set the previously focused element of the element to the focused element.

  • +
  • Run the dialog focusing steps for the dialog element.

  • @@ -57537,6 +57539,8 @@ interface HTMLDialogElement : HTMLElement { data-x="top-layer-add">add subject to subject's node document's top layer.

    +
  • Set the previously focused element of subject to the focused element.

  • +
  • Run the dialog focusing steps for subject.

  • @@ -57610,6 +57614,11 @@ interface HTMLDialogElement : HTMLElement {
  • If subject is in its Document's top layer, then remove it.

  • +
  • If the previously focused element element is not null, create a + temporary pointer points to the element, set the previously focused + element to null, run the focusing steps for the element pointed by the temporary pointer; + The viewport shouldn't be scrolled by doing this step.

  • +
  • Queue an element task on the user interaction task source given the subject element to fire an event named close at subject.

  • @@ -57644,6 +57653,11 @@ interface HTMLDialogElement : HTMLElement {

    Each dialog element has an is modal flag. When a dialog element is created, this flag must be set to false.

    +

    Each dialog element has a previously focused element which is null or + an element, and it is initially null. When showModal() and + show() are called, this element must be set to the currently + focused element before running the dialog focusing steps.

    +

    The open IDL From dcd4192e2d1a9c8039546ccb2a1a791b71ea46b2 Mon Sep 17 00:00:00 2001 From: Sean Feng Date: Tue, 20 Apr 2021 15:18:11 -0400 Subject: [PATCH 2/5] Address comments --- source | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source b/source index ba943e3f28f..f01e40d2793 100644 --- a/source +++ b/source @@ -57498,7 +57498,7 @@ interface HTMLDialogElement : HTMLElement {

  • Add an open attribute to the dialog element, whose value is the empty string.

  • -
  • Set the previously focused element of the element to the focused element.

  • +
  • Set the dialog element's previously focused element to the focused element.

  • Run the dialog focusing steps for the dialog element.

  • @@ -57539,7 +57539,7 @@ interface HTMLDialogElement : HTMLElement { data-x="top-layer-add">add subject to subject's node document's top layer.

    -
  • Set the previously focused element of subject to the focused element.

  • +
  • Set the subject's previously focused element to the focused element.

  • Run the dialog focusing steps for subject.

  • @@ -57614,10 +57614,10 @@ interface HTMLDialogElement : HTMLElement {
  • If subject is in its Document's top layer, then remove it.

  • -
  • If the previously focused element element is not null, create a - temporary pointer points to the element, set the previously focused - element to null, run the focusing steps for the element pointed by the temporary pointer; - The viewport shouldn't be scrolled by doing this step.

  • +
  • If the subject's previously focused element element is not null, create a + temporary pointer points to the element, set the previously focused element + to null, run the focusing steps for the element pointed by the temporary pointer; + the viewport should not be scrolled by doing this step.

  • Queue an element task on the user interaction task source given the subject element to fire an event named @@ -57653,9 +57653,9 @@ interface HTMLDialogElement : HTMLElement {

    Each dialog element has an is modal flag. When a dialog element is created, this flag must be set to false.

    -

    Each dialog element has a previously focused element which is null or +

    Each dialog element has a previously focused element which is null or an element, and it is initially null. When showModal() and - show() are called, this element must be set to the currently + show() are called, this element is set to the currently focused element before running the dialog focusing steps.


    From 0e310904b8d2ffeda0b2781885d07319237c88a1 Mon Sep 17 00:00:00 2001 From: Sean Feng Date: Thu, 22 Apr 2021 16:41:18 -0400 Subject: [PATCH 3/5] Address comments --- source | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/source b/source index f01e40d2793..c13f05895b1 100644 --- a/source +++ b/source @@ -57498,7 +57498,8 @@ interface HTMLDialogElement : HTMLElement {
  • Add an open attribute to the dialog element, whose value is the empty string.

  • -
  • Set the dialog element's previously focused element to the focused element.

  • +
  • Set the dialog element's previously focused element to the + focused element.

  • Run the dialog focusing steps for the dialog element.

  • @@ -57539,7 +57540,8 @@ interface HTMLDialogElement : HTMLElement { data-x="top-layer-add">add subject to subject's node document's top layer.

    -
  • Set the subject's previously focused element to the focused element.

  • +
  • Set the subject's previously focused element to the + focused element.

  • Run the dialog focusing steps for subject.

  • @@ -57614,10 +57616,15 @@ interface HTMLDialogElement : HTMLElement {
  • If subject is in its Document's top layer, then remove it.

  • -
  • If the subject's previously focused element element is not null, create a - temporary pointer points to the element, set the previously focused element - to null, run the focusing steps for the element pointed by the temporary pointer; - the viewport should not be scrolled by doing this step.

  • +
  • If subject's previously focused element is not null, then:

  • + +
      +
    1. Let element be subject's previously focused element. +

    2. +
    3. Set subject's previously focused element to null.

    4. +
    5. Run the focusing steps for element; the viewport should not be + scrolled by doing this step.

    6. +
  • Queue an element task on the user interaction task source given the subject element to fire an event named @@ -57654,8 +57661,8 @@ interface HTMLDialogElement : HTMLElement { element is created, this flag must be set to false.

    Each dialog element has a previously focused element which is null or - an element, and it is initially null. When showModal() and - show() are called, this element is set to the currently + an element, and it is initially null. When showModal() + and show() are called, this element is set to the currently focused element before running the dialog focusing steps.


    From aba402ff27449690e8b9c3d55da0f6c617e11065 Mon Sep 17 00:00:00 2001 From: Sean Feng Date: Thu, 22 Apr 2021 16:48:07 -0400 Subject: [PATCH 4/5] Wrap
      into
    1. --- source | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/source b/source index c13f05895b1..3a3a1e462bb 100644 --- a/source +++ b/source @@ -57616,15 +57616,17 @@ interface HTMLDialogElement : HTMLElement {
    2. If subject is in its Document's top layer, then remove it.

    3. -
    4. If subject's previously focused element is not null, then:

    5. +
    6. +

      If subject's previously focused element is not null, then:

      -

        -
      1. Let element be subject's previously focused element. -

      2. -
      3. Set subject's previously focused element to null.

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

      6. -
      +
        +
      1. Let element be subject's previously focused element. +

      2. +
      3. Set subject's previously focused element to null.

      4. +
      5. Run the focusing steps for element; the viewport should not be + scrolled by doing this step.

      6. +
      +
    7. Queue an element task on the user interaction task source given the subject element to fire an event named From 244306ee6cf14a9103c28a60c45a5dc3597694ae Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 27 Apr 2021 08:21:42 +0200 Subject: [PATCH 5/5] nits --- source | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source b/source index 3a3a1e462bb..590e83987c5 100644 --- a/source +++ b/source @@ -57498,7 +57498,7 @@ interface HTMLDialogElement : HTMLElement {

    8. Add an open attribute to the dialog element, whose value is the empty string.

    9. -
    10. Set the dialog element's previously focused element to the +

    11. Set the dialog element's previously focused element to the focused element.

    12. Run the dialog focusing steps for the dialog element.

    13. @@ -57620,9 +57620,11 @@ interface HTMLDialogElement : HTMLElement {

      If subject's previously focused element is not null, then:

        -
      1. Let element be subject's previously focused element. -

      2. +
      3. Let element be subject's previously focused + element.

      4. +
      5. Set subject's previously focused element to null.

      6. +
      7. Run the focusing steps for element; the viewport should not be scrolled by doing this step.