ToastRegion: no keyboard way back to a modal dialog after F6
Provide a general summary of the issue here
With a modal dialog open, F6 moves focus into the ToastRegion, but no key brings it back to the dialog.
🤔 Expected Behavior?
From the toast region, F6 (or Shift+F6, or Escape) returns focus to the element focused before F6, inside the modal dialog.
😯 Current Behavior
- F6 moves focus from the dialog to the toast region, as documented.
- F6 and Shift+F6 keep focus in the region: the rest of the page is inert under the modal, so the region is the only landmark.
- Escape does nothing.
- Tab past the last toast puts focus on
<body>, outside the dialog.
A keyboard user who checks a toast cannot get back to the dialog, other than by clicking.
💁 Possible Solution
When F6 has moved focus into the toast region from inside a modal, keep the element it came from. F6, Shift+F6 or Escape in the region returns focus there. This is what Base UI's toast viewport does.
🔦 Context
We wrap UNSTABLE_ToastRegion and UNSTABLE_ToastQueue in a design system. Its toasts must stay reachable, and leavable, by keyboard while a dialog is open.
🖥️ Steps to Reproduce
- Render a
ToastRegionand aDialogTriggerwith aModaland aDialogthat holds a button. - Open the dialog, then add a toast that has a button.
- With focus in the dialog, press F6: focus moves to the toast region.
- Press F6, then Shift+F6, then Escape: focus stays in the region each time.
- Press Tab past the toast's last button: focus lands on
<body>.
Version
react-aria-components 1.22.1
What browsers are you seeing the problem on?
Chrome
What operating system are you using?
macOS
I would've expected that Tab or Shift+Tab could bring it back. But maybe Dialogs should be landmarks in their own right as well. Will discuss with a11y and core team