-
Notifications
You must be signed in to change notification settings - Fork 2.9k
RFC: stopPropagation vs. preventDefault for escape #33750
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
Draft
smhigley
wants to merge
2
commits into
microsoft:master
Choose a base branch
from
smhigley:propagation-rfc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
docs/react-v9/contributing/rfcs/react-components/components/stopPropagation.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # RFC: using stopPropagation or preventDefault on escape-to-close events | ||
|
|
||
| --- | ||
|
|
||
| Contributors: @smhigley @bsunderhus | ||
|
|
||
| 28 January 2025 | ||
|
|
||
| ## Summary | ||
|
|
||
| This RFC discusses whether to preserve the removal of `event.stopPropagation()` in escape key events in #29262, affecting `Dialog`, `Menu`, `Popover`, and `Tooltip`. The `Combobox`, `Tagpicker`, and `Dropdown` controls all currently still use `event.stopPropagation()`. | ||
|
|
||
| ## Background | ||
|
|
||
| Prior to #29262 as well as in Fluent v8, controls used `event.stopPropagation()` when the `Escape` key was used to close a popup to prevent a single escape key press from closing multiple levels of popups (e.g. a popover in a dialog, or multiple levels of menus). This is also common practice in other control libraries such as Material, Semantic UI, or other teams within Microsoft (e.g. OWA, who reached out just before this RFC). We've also had a number of issues logged since the change: #28316, #28789, #30384, #30590, #33062. | ||
|
|
||
| On the other hand, the newer HTML `<dialog>` element and `popover` functionality do not automatically stop propagation of escape. In general `<dialog>`s should not be nested, but I've logged an issue for `popover` [on Open UI](https://github.com/openui/open-ui/issues/1147), since this issue has not yet been discussed. | ||
|
|
||
| After the change, our controls call `event.preventDefault()` instead of `event.stopPropagation()`, and we check `event.defaultPrevented` to handle multiple levels of popups. | ||
|
|
||
| ## Problem statement | ||
|
|
||
| By switching to `event.preventDefault()` and putting the onus on authoring teams to handle preventing cascade closures, we're going against the more common pattern used in v8, v0, and third party libraries, making interop more error-prone. It's also not an immediately apparent issue -- it's only found when a partner team both: | ||
|
|
||
| 1. Uses a Fluent v9 popup inside a not-v9 outer popup | ||
| 2. Tests closing the inner popup with the keyboard | ||
|
|
||
| On the other hand, using `event.stopPropagation` makes it harder for teams who want to listen to escape key events, even when they are consumed by a downstream control. One possible use case for this would be a marketing tracking script to determine how users are leaving a dialog on a granular level (i.e. measure escape behavior vs. close button click). With `stopPropagation`, it would be necessary to use the capture phase to catch escape dismissal. | ||
|
|
||
| ## Detailed Design or Proposal | ||
|
|
||
| This one is pretty simple, we have two options: | ||
|
|
||
| 1. Keep the current approach of calling `event.preventDefault()` and checking `event.defaultPrevented` | ||
| 2. Switch back to `event.stopPropagation()` | ||
|
|
||
| The one thing to note is that this RFC is narrowly scoped to only escape key keyboard events that are used to perform a close action, and no other events. | ||
|
|
||
| ### Pros and Cons | ||
|
|
||
| `preventDefault`: | ||
|
|
||
| - Is less opinionated about when & how partner teams should be able to listen to the escape key | ||
| - Not destructive / allows teams to opt in to stopping propagation for escape | ||
|
|
||
| `stopPropagation`: | ||
|
|
||
| - Follows the most common established pattern | ||
| - Interop with v8, v0, the HTML `<dialog>` element, and other non-Fluent controls | ||
| - No way to opt out of stopping propagation for escape | ||
|
|
||
| ## Open Issues | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
|
|
||
| No current open issues, but these are closed issues from partners asking about `stopPropagation`: | ||
|
|
||
| - #28316 | ||
| - #28789 | ||
| - #30384 | ||
| - #30590 | ||
| - #33062 | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.