WICG / close-watcher

A web API proposal for watching for close requests (e.g. Esc, Android back button, ...)
https://html.spec.whatwg.org/multipage/interaction.html#close-requests-and-close-watchers
71 stars 5 forks source link

Potential editorial improvement: give close watchers cancel and close actions #18

Closed domenic closed 2 years ago

domenic commented 2 years ago

In https://chromium-review.googlesource.com/c/chromium/src/+/3502624 @josepharhar stumbled across a mismatch between implementation and spec techniques that made me think we could improve the spec.

In particular, right now conceptual close watchers have close actions.

The close action for the CloseWatcher class's close watcher is to signal close. The close action for the <dialog> element's close watcher is to cancel the dialog.

These two close actions consist of very similar steps. Roughly:

We can probably move this infrastructure into the conceptual close watcher, by giving them "cancel actions" and "close actions", and then wrapping up that logic. This better ensures that all close watcher users actually do the correct thing with regard to checking whether cancel steps are allowed and consuming the user activation. And it makes it easier to write any future specs that use close watchers.