-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 requestClose()
function to HTMLDialogElement
#10164
Comments
This has come up in a few conversations but primarily from a discussion about adding a 'cancel' (nameTBD) action to invokers for dialogs, and also the light dismiss for dialog discussions. openui/open-ui#950 (reply in thread) - @domenic mentions that this is a useful functionality that we should probably expose. |
As I'm speccing and implementing light dismiss behaviors for I had been thinking this new However, non-modal dialogs don't get a close watcher. The "easy" thing is to say that Suggestions? Would we be ok with |
Non-modal dialogs can get a close watcher if the closedby value isn't in the none state (though that state is the default). Perhaps requestClose() should no-op or throw when in this state, for both modal and non-modal dialogs. |
Right. Sorry. I suppose I should have said that an exception gets thrown for a dialog whose |
I guess the three options are:
My initial hunch is that throwing is best but I might be wrong., |
Alternatively and this is just off the top of my head idea so apologies if I'm missing something obvious. Is it possible that perhaps dialogs should always have an internal close watcher and its enabled Boolean is what gets toggled by this new attribute? And then we just only care about that Boolean when processing close watchers? But not when calling the algorithms such as 'request to close' directly? This way existing non-modal dialogs wouldn't close on escape press but you could still reuse the close watcher infra for this function? |
Thanks for the thoughts. So I've spent today implementing the "throw" behavior, and adding it to the spec. After doing that, it feels pretty natural, and seems to have fewer footguns than either "no-op" or "fallthrough". Both of those seem like surprising (and semi-silent) behavior, vs. getting an exception that tells you exactly why things are weird. But please take a look at the new spec PR text #10737 and also the updated set of tests right here, and let me know what you think. |
1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329
1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026242 Auto-Submit: Mason Freed <[email protected]> Reviewed-by: David Baron <[email protected]> Commit-Queue: David Baron <[email protected]> Cr-Commit-Position: refs/heads/main@{#1384345}
1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026242 Auto-Submit: Mason Freed <[email protected]> Reviewed-by: David Baron <[email protected]> Commit-Queue: David Baron <[email protected]> Cr-Commit-Position: refs/heads/main@{#1384345}
…=testonly Automatic update from web-platform-tests Fix dialog.requestClose() in two ways 1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026242 Auto-Submit: Mason Freed <[email protected]> Reviewed-by: David Baron <[email protected]> Commit-Queue: David Baron <[email protected]> Cr-Commit-Position: refs/heads/main@{#1384345} -- wpt-commits: 6f4f09f92913154e70e9214636ee0e60c65f5d05 wpt-pr: 49223
…=testonly Automatic update from web-platform-tests Fix dialog.requestClose() in two ways 1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026242 Auto-Submit: Mason Freed <[email protected]> Reviewed-by: David Baron <[email protected]> Commit-Queue: David Baron <[email protected]> Cr-Commit-Position: refs/heads/main@{#1384345} -- wpt-commits: 6f4f09f92913154e70e9214636ee0e60c65f5d05 wpt-pr: 49223
…=testonly Automatic update from web-platform-tests Fix dialog.requestClose() in two ways 1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026242 Auto-Submit: Mason Freed <[email protected]> Reviewed-by: David Baron <[email protected]> Commit-Queue: David Baron <[email protected]> Cr-Commit-Position: refs/heads/main@{#1384345} -- wpt-commits: 6f4f09f92913154e70e9214636ee0e60c65f5d05 wpt-pr: 49223
…=testonly Automatic update from web-platform-tests Fix dialog.requestClose() in two ways 1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026242 Auto-Submit: Mason Freed <masonfchromium.org> Reviewed-by: David Baron <dbaronchromium.org> Commit-Queue: David Baron <dbaronchromium.org> Cr-Commit-Position: refs/heads/main{#1384345} -- wpt-commits: 6f4f09f92913154e70e9214636ee0e60c65f5d05 wpt-pr: 49223 UltraBlame original commit: 6b098292cbe3fd32f9a6e982d47edfdd882c84cc
…=testonly Automatic update from web-platform-tests Fix dialog.requestClose() in two ways 1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026242 Auto-Submit: Mason Freed <masonfchromium.org> Reviewed-by: David Baron <dbaronchromium.org> Commit-Queue: David Baron <dbaronchromium.org> Cr-Commit-Position: refs/heads/main{#1384345} -- wpt-commits: 6f4f09f92913154e70e9214636ee0e60c65f5d05 wpt-pr: 49223 UltraBlame original commit: 6b098292cbe3fd32f9a6e982d47edfdd882c84cc
…=testonly Automatic update from web-platform-tests Fix dialog.requestClose() in two ways 1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026242 Auto-Submit: Mason Freed <masonfchromium.org> Reviewed-by: David Baron <dbaronchromium.org> Commit-Queue: David Baron <dbaronchromium.org> Cr-Commit-Position: refs/heads/main{#1384345} -- wpt-commits: 6f4f09f92913154e70e9214636ee0e60c65f5d05 wpt-pr: 49223 UltraBlame original commit: 6b098292cbe3fd32f9a6e982d47edfdd882c84cc
…=testonly Automatic update from web-platform-tests Fix dialog.requestClose() in two ways 1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026242 Auto-Submit: Mason Freed <[email protected]> Reviewed-by: David Baron <[email protected]> Commit-Queue: David Baron <[email protected]> Cr-Commit-Position: refs/heads/main@{#1384345} -- wpt-commits: 6f4f09f92913154e70e9214636ee0e60c65f5d05 wpt-pr: 49223
…=testonly Automatic update from web-platform-tests Fix dialog.requestClose() in two ways 1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026242 Auto-Submit: Mason Freed <[email protected]> Reviewed-by: David Baron <[email protected]> Commit-Queue: David Baron <[email protected]> Cr-Commit-Position: refs/heads/main@{#1384345} -- wpt-commits: 6f4f09f92913154e70e9214636ee0e60c65f5d05 wpt-pr: 49223
…=testonly Automatic update from web-platform-tests Fix dialog.requestClose() in two ways 1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026242 Auto-Submit: Mason Freed <masonfchromium.org> Reviewed-by: David Baron <dbaronchromium.org> Commit-Queue: David Baron <dbaronchromium.org> Cr-Commit-Position: refs/heads/main{#1384345} -- wpt-commits: 6f4f09f92913154e70e9214636ee0e60c65f5d05 wpt-pr: 49223 UltraBlame original commit: 1f244e2980abb756ba68b021b1000a60e03d054e
…=testonly Automatic update from web-platform-tests Fix dialog.requestClose() in two ways 1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026242 Auto-Submit: Mason Freed <masonfchromium.org> Reviewed-by: David Baron <dbaronchromium.org> Commit-Queue: David Baron <dbaronchromium.org> Cr-Commit-Position: refs/heads/main{#1384345} -- wpt-commits: 6f4f09f92913154e70e9214636ee0e60c65f5d05 wpt-pr: 49223 UltraBlame original commit: 1f244e2980abb756ba68b021b1000a60e03d054e
…=testonly Automatic update from web-platform-tests Fix dialog.requestClose() in two ways 1. The prior implementation ignored the argument to requestClose. With this CL, requestClose(string) stores away string and then returns it from the CloseWatcher close event. 2. If the dialog's closedBy state is None (either explicitly or through the "Auto" state), requestClose throws an exception. I also added a more significant set of tests for requestClose() in all states. This goes along with recent discussion about throwing exceptions if requestClose() is called when the dialog isn't in the right state, relative to closedBy: whatwg/html#10164 (comment) The spec PR has been updated accordingly: whatwg/html#10737 Bug: 376516550 Change-Id: I023845844e6afb4da9a71637d517ac78d2861329 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6026242 Auto-Submit: Mason Freed <masonfchromium.org> Reviewed-by: David Baron <dbaronchromium.org> Commit-Queue: David Baron <dbaronchromium.org> Cr-Commit-Position: refs/heads/main{#1384345} -- wpt-commits: 6f4f09f92913154e70e9214636ee0e60c65f5d05 wpt-pr: 49223 UltraBlame original commit: 1f244e2980abb756ba68b021b1000a60e03d054e
What problem are you trying to solve?
Dialog elements have an internal close watcher which can trigger cancel events to give web developers a chance to prevent the closure. Currently there's no way for developers to get access to this functionality via anything other than the internal close watcher.
Developers will often want to trigger this same behaviour if closed through other mechanisms such as custom light dismiss for dialogs or even cancel buttons themselves.
What solutions exist today?
The developer would have to implement the cancellation logic twice once for the cancel event handler and another time for their custom cancel behaviour.
How would you solve it?
Exposing a new
requestClose()
function on dialogs that that simplified would be firing the cancel event and then firing close event (and associated dialog closing steps) if cancel wasn't prevented.Anything else?
The text was updated successfully, but these errors were encountered: