Draft
Conversation
to properly test this we need a way to trigger trusted keydown events in the browser
by simply not responding to onclose the CloseWatcher would be destroyed and not respond to future close attempts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This issue was first raised years ago in #875 when CloseWatcher was just a proposal. Now it is part of the official HTML spec. Chrome has been shipping this since v126 (June 2024) and Firefox has an implementation behind a feature flag.
This PR takes a progressive enhancement approach. If the API is available it is used instead of ordinary Escape
keydownevents for closing.However, there's a big potential pitfall with this naive approach: when a CloseWatcher emits a
closeevent, it will be destroyed and no further events emitted. This library's design is at odds with this, where consumers control the open state, and can choose not to respond to a requested close.The correct behavior from the CloseWatcher's perspective is to also listen to
cancelevents, and callpreventDefaulton those. This PR attempts to do that as long asshouldCloseOnEscis false, but there's nothing requiring consumers to pass that instead of simply deciding not to respond to aonRequestClosecallback. If consumers don't idiomatically passshouldCloseOnEscand instead just ignoreonRequestClose, the Escape/back key will not be able to close the modal after the first attempt, as the CloseWatcher would have been destroyed at that point.I believe strongly in adding support for
CloseWatcherto this package now, in spite of this pitfall. Perhaps we could introduce an additionalshouldCloseByCloseWatcherprop, to let consumers opt-in to the progressive enhancement of CloseWatcher? By starting with an opt-in approach, consumers can adjust their usage to always respect aonRequestClosecallback.Acceptance Checklist:
shouldCloseOnEsc={false}now also prevents closing with Android's back button.