Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ToggleEvents to <dialog>.showModal() #9733

Closed
keithamus opened this issue Sep 14, 2023 · 9 comments · Fixed by #10091
Closed

Add ToggleEvents to <dialog>.showModal() #9733

keithamus opened this issue Sep 14, 2023 · 9 comments · Fixed by #10091
Labels
addition/proposal New features or enhancements topic: dialog The <dialog> element topic: events

Comments

@keithamus
Copy link
Contributor

keithamus commented Sep 14, 2023

It is useful for web authors do determine when their <dialog> elements open and close. popover already has ToggleEvent which is dispatched when a popover opens or closes, but <dialog> does not. The current way to detect when a <dialog> opens is to register a mutation observer to check for open, however, this is quite a lot of work where an event would be easier.

I propose we add dispatching of ToggleEvent for <dialog> also. To be explicit: when showModal is called, <dialog> should dispatch a ToggleEvent with newState=open. When a dialog is closed (via form or button or close signal) it should dispatch a ToggleEvent with newState=closed.

Spec PR

@keithamus keithamus added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: dialog The <dialog> element agenda+ To be discussed at a triage meeting labels Sep 14, 2023
@lukewarlow
Copy link
Member

How about via show()? I assume it would also fire the toggle event?

@past past removed the agenda+ To be discussed at a triage meeting label Sep 15, 2023
@keithamus
Copy link
Contributor Author

keithamus commented Sep 15, 2023

During the WHATWG Triage Session at TPAC today, WHATWG has resolved that <dialog> will dispatch a cancelable beforetoggle event during open and non-cancelable during close, and non-cancelable toggle event an async tick after; similarly to how popover (and soon to be <details> - see #9743) will.

@keithamus keithamus removed the needs implementer interest Moving the issue forward requires implementers to express interest label Sep 15, 2023
@domenic
Copy link
Member

domenic commented Sep 15, 2023

Small correction: beforetoggle should be non-cancelable during close as well. (This matches popover.)

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 25, 2024
This patch implements beforetoggle and toggle events for dialog
elements. See spec issue: whatwg/html#9733

Bug: 1521813
Change-Id: I56e38230663990c8f1ed8ecd9307a6a881372605
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 25, 2024
This patch implements beforetoggle and toggle events for dialog
elements. See spec issue: whatwg/html#9733

Bug: 1521813
Change-Id: I56e38230663990c8f1ed8ecd9307a6a881372605
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 27, 2024
This patch implements beforetoggle and toggle events for dialog
elements. See spec issue: whatwg/html#9733

Bug: 1521813
Change-Id: I56e38230663990c8f1ed8ecd9307a6a881372605
@josepharhar
Copy link
Contributor

keith made a PR to implement this here: #10091
I wrote a chromium implementation here: https://chromium-review.googlesource.com/c/chromium/src/+/5238172

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 29, 2024
This patch implements beforetoggle and toggle events for dialog
elements. See spec issue: whatwg/html#9733

Bug: 1521813
Change-Id: I56e38230663990c8f1ed8ecd9307a6a881372605
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jun 28, 2024
This patch implements beforetoggle and toggle events for dialog
elements. See spec issue: whatwg/html#9733

Bug: 1521813
Change-Id: I56e38230663990c8f1ed8ecd9307a6a881372605
@teetotum
Copy link

teetotum commented Jul 4, 2024

The <dialog> element currently has a close event that authors can use to know that a dialog has closed (and run some code like removing event listeners).
A corresponding open event does not yet exist (although I hoped it would be added to the spec eventually).
How are the new toggle events related to the (already existing) close event and the (hypothetical) open event?

Am I correct to assume that a ToggleEvent: newState=closed would be equivalent to the close event for all intents and purposes and therefore it wouldn't really matter which one I would use? (edit: it seems there might be a slight difference in how they are raised by the platform (synchronous or via microtask); but this should not make a practical difference to consumers of these events)
And that a ToggleEvent: newState=open would be equivalent to the hypothetical open event?
And finally that the existence of a ToggleEvent would crush the last remaining hope that we will ever get a symmetrical open event corresponding to the close event?

@woody-li
Copy link

woody-li commented Aug 6, 2024

Is there any difference between show() and showModal().

@rejhgadellaa
Copy link

rejhgadellaa commented Aug 6, 2024

Yes, showModal() opens the dialog as a modal (blocks interaction with the document), show() does not:

The showModal() method of the HTMLDialogElement interface displays the dialog as a modal.
MDN

@woody-li
Copy link

woody-li commented Aug 6, 2024

@rejhgadellaa Thanks for your reply.
But I mean the toggle / beforetoggle event difference between show() and showModal().

I didn't find any difference in the descriptions below:

a Dialog's show() steps should dispatch a beforetoggle cancellable event
followed by a queuing a non-cancellable toggle event.
a Dialog's showModal() steps should dispatch a beforetoggle cancellable event
followed by a queuing non-cancellable toggle event.

@keithamus
Copy link
Contributor Author

The difference will be that event.target.matches(':modal') will be true for toggle when calling showModal() and beforetoggle when calling .close() on a :modal.

There will be a limitation that beforetoggle when opening a dialog as either show()/showModal() will be indistuingishable, and toggle will be indistinguishable when a dialog has closed.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Sep 26, 2024
This patch implements beforetoggle and toggle events for dialog
elements. See spec issue: whatwg/html#9733

Bug: 1521813
Change-Id: I56e38230663990c8f1ed8ecd9307a6a881372605
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Sep 26, 2024
This patch implements beforetoggle and toggle events for dialog
elements. See spec issue: whatwg/html#9733

Bug: 1521813
Change-Id: I56e38230663990c8f1ed8ecd9307a6a881372605
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5238172
Commit-Queue: Joey Arhar <[email protected]>
Reviewed-by: Keith Cirkel <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1360795}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Sep 26, 2024
This patch implements beforetoggle and toggle events for dialog
elements. See spec issue: whatwg/html#9733

Bug: 1521813
Change-Id: I56e38230663990c8f1ed8ecd9307a6a881372605
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5238172
Commit-Queue: Joey Arhar <[email protected]>
Reviewed-by: Keith Cirkel <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1360795}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Oct 2, 2024
…nts, a=testonly

Automatic update from web-platform-tests
Implement toggle events for dialog elements

This patch implements beforetoggle and toggle events for dialog
elements. See spec issue: whatwg/html#9733

Bug: 1521813
Change-Id: I56e38230663990c8f1ed8ecd9307a6a881372605
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5238172
Commit-Queue: Joey Arhar <[email protected]>
Reviewed-by: Keith Cirkel <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1360795}

--

wpt-commits: 30fc634d561c33720c78570e8b85a5360fa2faf6
wpt-pr: 44208
i3roly pushed a commit to i3roly/firefox-dynasty that referenced this issue Oct 2, 2024
…nts, a=testonly

Automatic update from web-platform-tests
Implement toggle events for dialog elements

This patch implements beforetoggle and toggle events for dialog
elements. See spec issue: whatwg/html#9733

Bug: 1521813
Change-Id: I56e38230663990c8f1ed8ecd9307a6a881372605
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5238172
Commit-Queue: Joey Arhar <[email protected]>
Reviewed-by: Keith Cirkel <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1360795}

--

wpt-commits: 30fc634d561c33720c78570e8b85a5360fa2faf6
wpt-pr: 44208
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Oct 3, 2024
…nts, a=testonly

Automatic update from web-platform-tests
Implement toggle events for dialog elements

This patch implements beforetoggle and toggle events for dialog
elements. See spec issue: whatwg/html#9733

Bug: 1521813
Change-Id: I56e38230663990c8f1ed8ecd9307a6a881372605
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5238172
Commit-Queue: Joey Arhar <[email protected]>
Reviewed-by: Keith Cirkel <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1360795}

--

wpt-commits: 30fc634d561c33720c78570e8b85a5360fa2faf6
wpt-pr: 44208
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Oct 9, 2024
…nts, a=testonly

Automatic update from web-platform-tests
Implement toggle events for dialog elements

This patch implements beforetoggle and toggle events for dialog
elements. See spec issue: whatwg/html#9733

Bug: 1521813
Change-Id: I56e38230663990c8f1ed8ecd9307a6a881372605
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5238172
Commit-Queue: Joey Arhar <jarharchromium.org>
Reviewed-by: Keith Cirkel <chromiumkeithcirkel.co.uk>
Cr-Commit-Position: refs/heads/main{#1360795}

--

wpt-commits: 30fc634d561c33720c78570e8b85a5360fa2faf6
wpt-pr: 44208

UltraBlame original commit: 0dc7b4fdaa7a8c8cabf38840e81de595c2b39e04
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Oct 9, 2024
…nts, a=testonly

Automatic update from web-platform-tests
Implement toggle events for dialog elements

This patch implements beforetoggle and toggle events for dialog
elements. See spec issue: whatwg/html#9733

Bug: 1521813
Change-Id: I56e38230663990c8f1ed8ecd9307a6a881372605
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5238172
Commit-Queue: Joey Arhar <jarharchromium.org>
Reviewed-by: Keith Cirkel <chromiumkeithcirkel.co.uk>
Cr-Commit-Position: refs/heads/main{#1360795}

--

wpt-commits: 30fc634d561c33720c78570e8b85a5360fa2faf6
wpt-pr: 44208

UltraBlame original commit: 0dc7b4fdaa7a8c8cabf38840e81de595c2b39e04
@annevk annevk closed this as completed in 0511ae0 Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements topic: dialog The <dialog> element topic: events
Development

Successfully merging a pull request may close this issue.

9 participants