From 128a87e7d96c34fb4a72c23623865a24ee23f9d5 Mon Sep 17 00:00:00 2001 From: Joey Arhar Date: Mon, 5 Feb 2024 13:45:33 -0800 Subject: [PATCH 1/9] Close dialog elements when the open attribute is removed Fixes https://github.com/whatwg/html/issues/5802 This patch adds attribute change steps to run the dialog closing steps whenever the open attribute is removed in order to prevent a bad state where the dialog is hidden but modal which renders the rest of the page inert. --- source | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/source b/source index dffcc9efcd2..c75aef9fef3 100644 --- a/source +++ b/source @@ -61051,9 +61051,23 @@ interface HTMLDialogElement : HTMLElement { +

The following attribute change + steps, given element, localName, oldValue, + value, and namespace are used for dialog elements:

+ +
    +
  1. If namespace is not null, then return.

  2. + +
  3. If localName is not open, then + return.

  4. + +
  5. If value is null, then close the dialog given + element.

  6. +
+

Removing the open attribute will usually hide the - dialog. However, doing so has a number of strange additional consequences: + dialog. However, doing so used to have a number of strange additional consequences:

@@ -65274,82 +65276,6 @@ interface HTMLDialogElement : HTMLElement {
  • Request to close the dialog this with returnValue and null.

  • - -

    To close the dialog with attribute changes given a dialog element - subject and a string or null result:

    - -
      -
    1. If returnValue is not given, then set it to null.

    2. - -
    3. Fire an event named beforetoggle, using ToggleEvent, with the oldState attribute initialized to "open" and the newState attribute - initialized to "closed" at subject.

    4. - -
    5. If subject does not have an open - attribute, then return.

    6. - -
    7. Queue a dialog toggle event task given subject, "open", and "closed".

    8. - -
    9. Remove subject's open - attribute.

    10. - -
    11. Run close the dialog given subject, result, and - false.

    12. -
    - -

    To close the dialog given a dialog element subject, a - string or null result, and a boolean preventFocus:

    - -
      -
    1. If the is modal flag of subject is true, then request an - element to be removed from the top layer given subject.

    2. - -
    3. Let wasModal be the value of subject's is - modal flag.

    4. - -
    5. Set the is modal flag of subject to false.

    6. - -
    7. If result is not null, then set the returnValue attribute to result.

    8. - -
    9. -

      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. If subject's node document's focused area of the - document's DOM anchor is a shadow-including inclusive - descendant of element and preventFocus is false, or - wasModal is true and preventFocus is false, then run the focusing - steps for element; the viewport should not be scrolled by doing this - step.

      6. -
      -
    10. - -
    11. Queue an element task on the user interaction task source given the - subject element to fire an event named - close at subject.

    12. - -
    13. -

      If subject's close watcher is not null, - then:

      - -
        -
      1. Destroy subject's close watcher.

      2. - -
      3. Set subject's close watcher to - null.

      4. -
      -
    14. -
    @@ -65611,7 +65537,7 @@ interface HTMLDialogElement : HTMLElement {
  • closeAction being to close the dialog given dialog, dialog's request close return - value, and dialog's request close source element.

  • + value, dialog's request close source element, and false.

  • getEnabledState being to return true if dialog's enable close watcher for request close is true or @@ -65649,14 +65575,14 @@ interface HTMLDialogElement : HTMLElement { data-x="attr-button-command-close-state">Close state and element has an open attribute, then close the dialog element with source's optional - value and source.

  • + value and source, and false.

  • If command is in the Request Close state and element has an open attribute, then request to close the dialog element with - source's optional value and - source.

  • + source's optional value, + source, and false.

  • If command is the Show Modal state and element does @@ -65690,12 +65616,12 @@ interface HTMLDialogElement : HTMLElement {

    When a dialog element subject is to be closed, with null or a string result and an Element or null - source, run these steps:

    + dialog">closed, with null or a string result, an Element or null + source, and a boolean removingOpenAttribute, run these steps:

    1. If subject does not have an open - attribute, then return.

    2. + attribute and removingOpenAttribute is false, then return.

    3. Fire an event named beforetoggle, using ToggleEvent, with the HTMLDialogElement : HTMLElement { subject.

    4. If subject does not have an open - attribute, then return.

    5. + attribute, and removingOpenAttribute is false, then return.

    6. Queue a dialog toggle event task given subject, "open", "closed", and source.

    7. -
    8. Remove subject's open - attribute.

    9. +
    10. If removingOpenAttribute is false, then remove subject's open attribute.

    11. If is modal of subject is true, then request an element to be removed from the top layer given subject.

    12. @@ -65730,7 +65656,8 @@ interface HTMLDialogElement : HTMLElement {
    13. Set subject's request close source element to null.

    14. -

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

      +

      If subject's previously focused element is not null and + removingOpenAttribute is false, then:

      1. Let element be subject's previously focused