[dialog] Fix confirmation return focus#5024
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,217.74 ms -26.36 ms(-2.1%) | Renders: 50 (+0) | Paint: 1,824.89 ms -53.62 ms(-2.9%)
11 tests within noise — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
Fixes a focus restoration edge case in Base UI’s floating focus management where an outside-press (backdrop) can temporarily blur focus to document.body, causing a subsequently opened “close confirmation” dialog to restore focus to the original trigger instead of back into the still-open modal.
Changes:
- Record the last focused element inside the floating element when focus is lost with no concrete
relatedTarget(e.g. blur-to-body on backdrop press). - Add a browser-only regression test covering the “outside press → canceled close → confirmation dialog → Go back → focus returns into dialog” flow.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
packages/react/src/floating-ui-react/components/FloatingFocusManager.tsx |
Records the focused element when focus is lost to no relatedTarget, enabling correct focus restoration after a transient blur-to-body. |
packages/react/src/dialog/root/DialogRoot.test.tsx |
Adds a non-JSDOM regression test validating focus returns into the dialog after closing an outside-press confirmation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The new Drawer close confirmation demo exposed a focus restore bug: after canceling an outside-press close and opening a confirmation dialog, choosing “Go back” could send focus back to the original trigger instead of the field inside the still-open dialog/drawer.
Steps
https://deploy-preview-5024--base-ui.netlify.app/react/components/drawer#close-confirmation
Root cause
When the outside press blurred the focused field to the document body, the detached confirmation dialog had no useful pre-open focus target to restore.
Changes