Repository navigation
[navigation menu] Fix reverse shift-tab submenu re-entry - #4464
Conversation
commit: |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Bundle size report
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. |
flaviendelangle
left a comment
There was a problem hiding this comment.
afterOutside focus guard fix
The root cause is that when focus leaves the viewport, the viewport's onBlur handler sets viewportInert = true, making the viewport inert on inline (non-portaled) menus. When the user Shift+Tabs back, isTabbable() returned false and focus fell back to the trigger.
The flushSync approach is the right call here — it ensures React commits the inert removal to the DOM before the .focus() call, which is necessary since we're inside an event handler that would otherwise batch the state update. The scope of the re-render is small (just the viewport's inert attribute), so the perf cost is negligible.
Minor observations
-
Asymmetry with
beforeOutsideguard: ThebeforeOutsideguard simply callsbeforeInsideRef.current?.focus()without clearing inert state. I believe this works because Shift+Tabbing backward hitsbeforeOutsidebefore leaving the viewport scope, so the viewport isn't inert yet. Worth confirming this reasoning holds in all cases — if thebeforeOutsidecase can also encounter an inert viewport, it would need the sameflushSynctreatment. -
Fallback behavior change: The old code gated on
isTabbable(afterInsideRef.current)before focusing it. The new code usesafterInsideRef.current || triggerElement. Since theflushSyncensures the viewport is no longer inert,afterInsideRef.currentshould always be focusable when it exists, so dropping theisTabbablegate is safe. But ifafterInsideRef.currentexists yet is somehow not focusable for another reason, focus would silently land on a non-tabbable element instead of falling back to the trigger. Seems unlikely but is a subtle behavioral change.
Verdict
Overall looks good to merge.
Codex Review (GPT-5.4)I reviewed the full PR diff against a freshly fetched 1. Bugs / Issues (None)I did not find any concrete correctness, accessibility, or regression issues in the current patch. 2. Root Cause & Patch Assessment
6. Test Coverage AssessmentThe added tests meaningfully improve coverage for the boundary that was previously missing: reverse-tabbing after focus has already left the submenu. I also reran targeted validation on the current PR head with Merge Confidence ScoreOverall merge confidence is 4/5. The patch is small, the root cause looks correctly addressed for both portaled and inline submenu flows, and the targeted browser/jsdom/type validation is strong for this bug class. I would be comfortable merging this as-is. |
Fixes #4463
This fixes reverse tab re-entry in Navigation Menu submenus so focus returns to the last submenu item instead of falling back to the trigger or disappearing in inline nested submenus.
Changes
afterOutsidefocus guard to re-enter the submenu through the inside guard and synchronously clear inline viewport inert state before redirecting focus.