Skip to content

Conversation

@mfreed7
Copy link
Collaborator

@mfreed7 mfreed7 commented Oct 31, 2024

This adds a few things:

  • A closedby attribute that can be used to control the light dismiss behavior of dialogs:

    1. <dialog closedby=none> - no user-triggered closing of dialogs at all.
    2. <dialog closedby=closerequest> - user pressing ESC (or other close trigger) closes the dialog
    3. <dialog closedby=any> - user clicking outside the dialog, or pressing ESC, closes the dialog. Akin to popover=auto behavior.
    4. <dialog> - i.e. no closedby attribute - default/old behavior. Behaves like closedby=closerequest for modal dialogs, and closedby=none for modeless dialogs.
  • This PR also (per the request) adds a dialog.requestClose() which fires the cancel event, and then (if that isn't cancelled) fires the close event and closes the dialog.

  • I also consolidated the "light dismiss" activities into one algorithm, which will need to be called by Add popover light dismiss integration w3c/pointerevents#460 if that ever gets some attention.

Some interesting related links:

Closes #9373

(See WHATWG Working Mode: Changes for more details.)


/dnd.html ( diff )
/dom.html ( diff )
/index.html ( diff )
/indices.html ( diff )
/infrastructure.html ( diff )
/interaction.html ( diff )
/interactive-elements.html ( diff )
/popover.html ( diff )
/semantics-other.html ( diff )

@domenic
Copy link
Member

domenic commented Nov 1, 2024

This is exciting! Unfortunately I am going OOO for a week starting ~now, so won't get a chance to review too soon. Hopefully others will be able to help with some reviews, but I would like to get a chance to carefully review the close watcher integration, etc. before this lands.

Would you mind commenting on what approach you took to the mutability of the closedby attribute? We discussed that a bit in #9373, and I think we came up with a tentative proposal, but I'm not sure it was battle-tested.

@keithamus
Copy link
Member

Would you mind commenting on what approach you took to the mutability of the closedby attribute? We discussed that a bit in #9373, and I think we came up with a tentative proposal, but I'm not sure it was battle-tested.

Looks like CloseWatchers get a mutable enabled value, which is toggled whenever closedby is set to the applicable values - when false it skips the events and returns early. IMO this seems to nicely side-skirt the stacking issues around mutation of the attribute without adding lots of complexity in either the consuming elements and/or having some messy algorithms to insert mid-way into a stack.

Copy link
Member

@keithamus keithamus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me!

@mfreed7
Copy link
Collaborator Author

mfreed7 commented Nov 1, 2024

This is exciting! Unfortunately I am going OOO for a week starting ~now, so won't get a chance to review too soon. Hopefully others will be able to help with some reviews, but I would like to get a chance to carefully review the close watcher integration, etc. before this lands.

That's totally fine - no rush. I did this one in the opposite order that I usually do: spec first, prototype after. So I'm moving on to prototype it now, which might reveal other flaws. But I thought since @lukewarlow had gotten the spec into such decent shape, that I'd clean it up and open the PR in case folks saw other flaws there that I could address in the prototype.

Would you mind commenting on what approach you took to the mutability of the closedby attribute? We discussed that a bit in #9373, and I think we came up with a tentative proposal, but I'm not sure it was battle-tested.

As @keithamus said, I just kept what @lukewarlow did in the original PR, and used a new enabled state on CloseWatcher. I haven't implemented that yet, but it seems reasonably straightforward. But let me know if you see any flaws.

@annevk annevk added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest needs tests Moving the issue forward requires someone to write tests topic: dialog The <dialog> element labels Nov 5, 2024
source Outdated
Comment on lines 61702 to 61707
<p>The <code data-x="attr-dialog-closedby">closedby</code> attribute's <i data-x="invalid value
default">invalid value default</i> and <i data-x="missing value default">missing value
default</i> are both the <dfn data-x="attr-closedby-auto-state">Auto</dfn> state. The <span
data-x="attr-closedby-auto-state">auto</span> state matches <span
data-x="attr-closedby-closerequest-state">closerequest</span> when the element is modal;
otherwise <span data-x="attr-closedby-none-state">none</span>.</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's very inconsistent spelling of states here. They should match the capitalization and words of how they are introduced. And should typically be followed by the word state (though that's not linked).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, perhaps the statement of fact is better as a note?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's very inconsistent spelling of states here. They should match the capitalization and words of how they are introduced. And should typically be followed by the word state (though that's not linked).

Yep, I agree. I fixed them all up, I think. Please let me know if you see any others I missed. All are now lowercase.

Also, perhaps the statement of fact is better as a note?

Sorry - can you help me understand this? Which "statement of fact"?

@mfreed7
Copy link
Collaborator Author

mfreed7 commented Jan 9, 2025

Gentle ping on this PR. All checkboxes are checked and it has an editor approval.

@lukewarlow
Copy link
Member

Fwiw regarding implementor interest I raised mozilla/standards-positions#998 and WebKit/standards-positions#329

@mfreed7
Copy link
Collaborator Author

mfreed7 commented Jan 9, 2025

Fwiw regarding implementor interest I raised mozilla/standards-positions#998 and WebKit/standards-positions#329

Oh, thanks! I didn't realize those had been filed. I added them to the OP block.

@domenic domenic merged commit 8029d4f into whatwg:main Jan 15, 2025
2 checks passed
@domenic
Copy link
Member

domenic commented Jan 15, 2025

Back from vacation, and merged! Please remember to send a PR renaming the tests from .tentative.

@domenic domenic added normative change topic: close watchers and removed needs implementer interest Moving the issue forward requires implementers to express interest needs tests Moving the issue forward requires someone to write tests labels Jan 15, 2025
@stof
Copy link

stof commented Jan 15, 2025

Would closedBy=any also close when clicking on the backdrop pseudo-element or is it not considered a click outside the dialog ?

@lukewarlow
Copy link
Member

Would closedBy=any also close when clicking on the backdrop pseudo-element or is it not considered a click outside the dialog ?

Yes, that closes the dialog. Here's a demo you can play around with in Chrome canary (w/ experimental web flag): https://jsfiddle.net/vco1mdth/

@lukewarlow
Copy link
Member

PR to remove tentative from tests at web-platform-tests/wpt#50100

@mfreed7
Copy link
Collaborator Author

mfreed7 commented Jan 15, 2025

Back from vacation, and merged! Please remember to send a PR renaming the tests from .tentative.

Welcome back, and thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

Add light dismiss functionality to <dialog>

7 participants