Repository navigation
Conversation
xyrolle
requested review from
atomiks,
colmtuite,
flaviendelangle,
jjenzz and
michaldudak
as code owners
October 16, 2026 13:31
commit: |
Bundle size
PerformanceTotal duration: 376.29 ms -9.82 ms(-2.5%) | Renders: 75 (+0) | Paint: 662.76 ms -23.38 ms(-3.4%) No significant changes — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #6012
What
FloatingFocusManagerresolves its initial focus in a microtask and normally applies it on the next frame (synchronously when a virtual screen-reader press opened the popup). When the microtask finds focus on an element inside the floating element, other than the floating element itself, that focus is now kept:initialFocusref or function. This matches focus that was already inside before the open effect, which is also kept whatever the target.initialFocus={false}and aninitialFocusfunction returningundefinedare unchanged, because the microtask returns before this point. Focus on the floating element itself is still moved to the initial target, as before.activeElementis the body or null (for example because the focused element was removed). It then focuses the resolved initial target, as onmaster. It is not guaranteed to run: as before, a laterenqueueFocuscall cancels it, and the existing open-state guard still skips it if the popup has closed. After a virtual screen-reader press the request runs at once instead, and finds the focus still in place.Why
If focus reaches an element inside after the open effect and before the microtask,
hadFocusInsideistrue, andshouldFocusthen returnstrueunconditionally. So the queued request forces focus onto the initial target and the user's next keystrokes go elsewhere.The neighbouring cases are already handled. Focus inside before the effect is caught by
focusAlreadyInsideFloatingEl. Focus that moves inside after the microtask is caught by thefocusMovedInsideguard from #4775, which only applies when the microtask observed focus outside. This change covers the interval between the two.The regression tests move focus programmatically in that interval. A reproduction through a native browser interaction has not been verified.
How
A new
focusMovedInsideBeforeResolveflag sits next to the existinghadFocusInside. When it is set,shouldFocusreturns whether focus has been lost (activeElementis the body or null), instead oftrue.Test harness change
test/setupVitest.tsreplaces jsdom'srequestAnimationFramewith asetTimeoutthat always returned0, socancelAnimationFramenever cancelled anything. It now returns the timer as the handle and cancels it withclearTimeout, as a browser does.Two
useListNavigationgrid tests ("focuses previous item … skipping disabled items") failed with this change under the old harness. The cause is jsdom-only:enqueueFocuscancels in a browser still fired in jsdom.master, the manager's forced re-focus put focus back.So these tests do not justify forcing the re-focus in a browser. They pass because the harness now cancels as a browser does.
Overlaps
enqueueFocusqueue with this change and also discusses jsdom's non-cancelling frames. The combined behaviour has not been verified.onInitiallyFocusedcallback. It runs after theshouldFocusgate, so when this change keeps the focus, that callback does not run either.PopupFocusManagerrename, will need integration work.How it was tested
A new
describe, "focus that moved inside before the initial focus resolved", runs in jsdom and in Chromium (Vitest browser mode). Five of its tests hold frames in a cancellable queue and run them by hand. One waits for unheld frames instead: native frames in Chromium, and in jsdom the harness's timer-backedrequestAnimationFramedescribed above. Its cases:To run it:
On
master, 5 of the 6 fail and the fall-back case passes, in both environments. With the fix, all 6 pass in both. In jsdom only (it was not run in Chromium), the first version of this fix, which re-focused the element captured by the microtask, fails the SVG, later-move and lost-focus cases.On the final commit:
@base-ui/react,@base-ui/utils, docs): 380 files, 9311 passed, 1500 skipped, 0 failed;eslint --max-warnings 0andprettier --checkon the changed files, andpnpm typescriptat the root: clean.No CSS changed, so stylelint does not apply.
I have followed (at least) the PR section of the contributing guide.