Focused Toast removal with `Escape` key broken after `1.1.6-rc.1`
Bug report
Current Behavior
https://github.com/radix-ui/primitives/assets/36169811/44f5b28b-01fd-4034-a42f-cce957faf0cf
Currently, when more than 2 toasts are visible, and focus is move to the oldest toast, when clicking Escape, 2 Toasts are getting removed instead of the focused toast.
Expected behavior
Expectation is that only the focused toast is removed.
Reproducible example
- Open 3 toasts
- Move focus to the middle toast
- Press Escape
- 2 toasts are removed instead of a single, currently focused toast.
Suggested solution
According to my investigation (might be wrong though), after making the useEscapeKeyDown handler a capturing event listener, the order in which event handlers responsible for toast focus management are fired is reversed.
Previously:
Now:
This causes the ref flags to not be set in a correct ore
Additional context
The bug is caused by https://github.com/radix-ui/primitives/pull/2761
Your environment
| Software | Name(s) | Version |
|---|---|---|
| Radix Package(s) | @radix-ui/toast | 1.1.6-rc.1 |
| React | n/a | latest |
| Browser | Chrome | 125 |
| Assistive tech | ||
| Node | n/a | |
| npm/yarn | ||
| Operating System | MacOS | 14.4.1 |
This is also happening under recently released @radix-ui/[email protected]