Skip to content

[all components] Skip CSS-hidden composite items in keyboard navigation - #4195

Merged
atomiks merged 1 commit into
mui:masterfrom
atomiks:codex/fix-menu-hidden-items-4193
Mar 5, 2026
Merged

atomiks merged 1 commit into
mui:masterfrom
atomiks:codex/fix-menu-hidden-items-4193

Conversation

@atomiks

@atomiks atomiks commented Feb 25, 2026 •

Copy link
Copy Markdown
Contributor

Note on perf: this check only happens in events (measured <0.1ms increase per event on a slow device) or on open for focus sync where the cost is O(k) depending on how many items are disabled (the items need to be scanned to find the first enabled/non-hidden item) but k is very low in practice. So overhead is ~nonexistent.

Fixes #4193

@atomiks atomiks added type: bug It doesn't behave as expected. scope: all components Widespread work has an impact on almost all components. labels Feb 25, 2026
@pkg-pr-new

pkg-pr-new Bot commented Feb 25, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/@base-ui/react@4195
    
    pnpm add https://pkg.pr.new/@base-ui/utils@4195
    

commit: 6e3ac07

@mui-bot

mui-bot commented Feb 25, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+217B(+0.05%) 🔺+110B(+0.07%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Feb 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit a5b08f7
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69a93f98ca88f000081695eb
😎 Deploy Preview https://deploy-preview-4195--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks marked this pull request as ready for review February 25, 2026 22:12
@atomiks

atomiks commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Codex Review

Overview

This branch makes CSS-hidden items non-focusable in both arrow-key navigation and Menu typeahead, including the text-navigation path. It also simplifies the typeahead match loop to avoid per-key index-array allocations and centralizes visibility checks.

Findings

No blocking issues found in this patch.

1. ℹ️ [Informational] Grid navigation still dominates keyboard cost at 5,000 items

Impact: The main runtime cost is still grid-event preparation work, not menu open/list navigation. The hidden-item check adds work in that path because disabled checks are executed many times per key event.

Evidence: useListNavigation still rebuilds grid structures on each key event (packages/react/src/floating-ui-react/hooks/useListNavigation.ts:635), and hidden-item checks run through isListIndexDisabled (packages/react/src/floating-ui-react/utils/composite.ts:442). In a 5,000-item stress run on contained-triggers, comparing master (a42221c8f) vs head (3de6c671a):

Browser Scenario Ref Mean ms/event p95 ms/event isListIndexDisabled calls/event
Chromium list_open master 0.00008 0.00020 1
Chromium list_open head 0.00016 0.00040 1
Chromium list_event master 0.00004 0.00020 1
Chromium list_event head 0.00016 0.00020 1
Chromium grid_event master 14.61 17.17 10002
Chromium grid_event head 17.69 19.30 10002
Firefox grid_event master 6.27 6.67 10002
Firefox grid_event head 8.73 9.33 10002
WebKit grid_event master 6.20 6.67 10002
WebKit grid_event head 7.73 8.00 10002

Recommendation: Keep this patch for correctness, and treat grid-event optimization as follow-up work if more headroom is needed (cache/reuse per-grid derived data where possible).

2. ℹ️ [Informational] Typeahead loop change improves hit-path cost but worsens miss-path cost on Chromium/Firefox

Impact: The new wrapped loop in useTypeahead removes per-key index-array allocations, which helps in common hit cases. In no-match scans, it was slower in Chromium/Firefox in this micro-check.

Evidence: Typeahead now scans in-place with a wrapped index loop and visibility filtering (packages/react/src/floating-ui-react/hooks/useTypeahead.ts:120), with Menu passing elements for visibility filtering (packages/react/src/menu/root/MenuRoot.tsx:464). In the same 5,000-item run:

Browser Scenario Ref Mean ms/event p95 ms/event Samples
Chromium typeahead_event_hit master 0.0090 0.0095 5
Chromium typeahead_event_hit head 0.0002 0.0005 5
Chromium typeahead_event_miss master 0.0739 0.0745 5
Chromium typeahead_event_miss head 0.6801 0.6955 5
Firefox typeahead_event_hit master 0.0280 0.0350 5
Firefox typeahead_event_hit head 0.0010 0.0050 5
Firefox typeahead_event_miss master 0.2300 0.2400 5
Firefox typeahead_event_miss head 1.2020 1.3000 5
WebKit typeahead_event_hit master 0.0250 0.0450 5
WebKit typeahead_event_hit head 0.0020 0.0050 5
WebKit typeahead_event_miss master 8.2810 8.4100 5
WebKit typeahead_event_miss head 4.7460 4.7700 5

Recommendation: Keep the current implementation for correctness and allocation reduction, and monitor miss-path behavior on Chromium/Firefox in realistic interaction traces if this becomes user-visible.

Confidence: 4/5

High confidence based on full-branch review, targeted regression tests, and fresh master vs head browser benchmarks using the same perf-check shape as the existing review.

Notes

  • Full-branch scope reviewed: upstream/master...HEAD.
  • Perf method: browser-side stress micro-bench on deploy preview experiments/perf/contained-triggers with ~30k DOM nodes and 5,000-item synthetic lists/grids.
  • Targeted verification run:
    • VITEST_ENV=jsdom pnpm -s vitest run --project @base-ui/react packages/react/src/floating-ui-react/hooks/useTypeahead.test.tsx
    • VITEST_ENV=chromium pnpm -s vitest run --project @base-ui/react packages/react/src/menu/root/MenuRoot.test.tsx -t "text navigation|skips items hidden with CSS during keyboard navigation"
    • VITEST_ENV=jsdom pnpm -s vitest run --project @base-ui/react packages/react/src/floating-ui-react/hooks/useListNavigation.test.tsx -t "skips items hidden with CSS in navigation|falls back left in a partial last row when the preferred candidate is disabled"
    • VITEST_ENV=jsdom pnpm -s vitest run --project @base-ui/react packages/react/src/floating-ui-react/components/FloatingFocusManager.test.tsx

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 5, 2026
@atomiks
atomiks force-pushed the codex/fix-menu-hidden-items-4193 branch from 70cf9ce to 23f1da1 Compare March 5, 2026 04:32
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 5, 2026
@atomiks
atomiks force-pushed the codex/fix-menu-hidden-items-4193 branch from 5a50473 to a5b08f7 Compare March 5, 2026 08:32
@atomiks
atomiks merged commit 7a50199 into mui:master Mar 5, 2026
6 checks passed
@atomiks
atomiks deleted the codex/fix-menu-hidden-items-4193 branch March 5, 2026 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: all components Widespread work has an impact on almost all components. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Menu] Menu items hidden with CSS are not removed from tab order

2 participants