Description
On MS Edge Explainers #457, @mfreed7 asked:
During implementation, the question has come up about whether the Escape key light dismiss behavior (or really, any of the light dismiss behavior such as clicking outside) should be author-cancellable. I.e. user hits Escape, but author has added 'keydown' event handler on document.body, and does preventDefault(). Should the currently-top popup be hidden?
@domenic said:
First, I think the platform needs to have both author-cancelable and non-cancelable close signals. Notably, exiting fullscreen cannot be author-cancelable. But, exiting a
<dialog>
is (and we have some strong feedback that it should continue to be).Second, I think that the behavior should be uniform. So, you can prevent dialog closing by
preventDefault()
ing Esc ondocument
. It also has an explicitcancel
event which can bepreventDefault()
ed. (But, itsclose
cannot bepreventDefault()
ed; that happens after the fact.) This means that, IMO, anything with cancelable close behavior should behave the same way, both in terms ofkeydown
event listeners (on desktop) and also having acancel
event where applicable.(Note: the modal close signals explainer was written before I realized this about dialog. Per slightlyoff/history_api#13, we're probably going to update the event name for
ModalCloseWatcher
in the way the above paragraph discusses, i.e. changebeforeclose
tocancel
, to match<dialog>
. Maybe we'll even rename it toModalCancelWatcher
.)I don't have a strong opinion on which category
<popup>
should go in. @melanierichards mentioned in #455 that the current plan is for it to be in the uncancelable category. If so, then I think it should behave like fullscreen and keydown listeners shouldn't be able to stop it, and it shouldn't have acancel
event, etc.Now, there's an interesting wrinkle for author-cancelable close signals regarding the Android back button, which is that canceling them can be used to trap the user by disabling the back button. Our modal close signals explainer has some mitigations for this, and for platform predictability, it applies those mitigations on all platforms.