Skip to content

Commit c2a9b9c

Browse files
committed
rfc for stopPropagation vs. preventDefault for escape
1 parent 4f791b3 commit c2a9b9c

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# RFC: using stopPropagation or preventDefault on escape-to-close events
2+
3+
---
4+
5+
Contributors: @smhigley @bsunderhus
6+
7+
28 January 2025
8+
9+
## Summary
10+
11+
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()`.
12+
13+
## Background
14+
15+
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.
16+
17+
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.
18+
19+
After the change, our controls call `event.preventDefault()` instead of `event.stopPropagation()`, and we check `event.defaultPrevented` to handle multiple levels of popups.
20+
21+
## Problem statement
22+
23+
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:
24+
25+
1. Uses a Fluent v9 popup inside a not-v9 outer popup
26+
2. Tests closing the inner popup with the keyboard
27+
28+
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.
29+
30+
## Detailed Design or Proposal
31+
32+
This one is pretty simple, we have two options:
33+
34+
1. Keep the current approach of calling `event.preventDefault()` and checking `event.defaultPrevented`
35+
2. Switch back to `event.stopPropagation()`
36+
37+
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.
38+
39+
### Pros and Cons
40+
41+
`preventDefault`:
42+
43+
- Is less opinionated about when & how partner teams should be able to listen to the escape key
44+
45+
`stopPropagation`:
46+
47+
- Follows the most common established pattern
48+
- Interop with v8, v0, the HTML `<dialog>` element, and other non-Fluent controls
49+
50+
## Open Issues
51+
52+
No current open issues, but these are closed issues from partners asking about `stopPropagation`:
53+
54+
- #28316
55+
- #28789
56+
- #30384
57+
- #30590
58+
- #33062

0 commit comments

Comments
 (0)