Skip to content

[useListNavigation] Ignore disabled item on initial focusing - #2604

Merged
mnajdova merged 4 commits into
mui:masterfrom
mnajdova:useListNavigation/ignore-disabled-idx-initially
Oct 6, 2025
Merged

mnajdova merged 4 commits into
mui:masterfrom
mnajdova:useListNavigation/ignore-disabled-idx-initially

Conversation

@mnajdova

@mnajdova mnajdova commented Sep 1, 2025 •

Copy link
Copy Markdown
Member

Same as #2579, but for components that use useListNavigation. Namely, initially the first non-disabled item is highlighted when opening the list - it's still possible to focus disabled items afterwards.

In order for this to work, we still propagate empty disabledIndices as an option, but the hook skips the disabled items on initial focus.

@mnajdova mnajdova added type: bug It doesn't behave as expected. accessibility a11y labels Sep 1, 2025
@pkg-pr-new

pkg-pr-new Bot commented Sep 1, 2025 •

Copy link
Copy Markdown

vite-css-base-ui-example

pnpm add https://pkg.pr.new/mui/base-ui/@base-ui-components/react@2604
pnpm add https://pkg.pr.new/mui/base-ui/@base-ui-components/utils@2604

commit: ff68fd8

@mui-bot

mui-bot commented Sep 1, 2025 •

Copy link
Copy Markdown

Bundle size report

Total Size Change: ▼-86B(-0.01%) - Total Gzip Change: 🔺+3B(0.00%)
Files: 69 total (0 added, 0 removed, 4 changed)

Show details for 69 more bundles

@base-ui-components/react/context-menu parsed: ▼-22B(-0.02%) gzip: 🔺+3B(+0.01%)
@base-ui-components/react/menu parsed: ▼-22B(-0.02%) gzip: 🔺+1B(0.00%)
@base-ui-components/react/select parsed: ▼-22B(-0.02%) gzip: ▼-2B(0.00%)
@base-ui-components/react parsed: ▼-20B(-0.01%) gzip: 🔺+1B(0.00%)
@base-ui-components/react/accordion parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/alert-dialog parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/avatar parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/checkbox parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/checkbox-group parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/collapsible parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/dialog parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/direction-provider parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/field parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/fieldset parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/form parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/input parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/menubar parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/merge-props parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/meter parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/navigation-menu parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/number-field parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/popover parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/preview-card parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/progress parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/radio parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/radio-group parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/scroll-area parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/separator parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/slider parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/switch parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/tabs parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/toast parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/toggle parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/toggle-group parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/toolbar parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/tooltip parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/types parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/unstable-no-ssr parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/unstable-use-media-query parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/react/use-render parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/detectBrowser parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/error parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/fastObjectShallowCompare parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/generateId parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/getReactElementRef parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/inertValue parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/isElementDisabled parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/isMouseWithinBounds parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/mergeObjects parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/owner parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/reactVersion parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/safeReact parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/store parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useAnimationFrame parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useControlled parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useEnhancedClickHandler parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useEventCallback parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useForcedRerendering parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useId parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useInterval parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useIsoLayoutEffect parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useLatestRef parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useMergedRefs parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useOnFirstRender parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useOnMount parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useRefWithInit parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/useTimeout parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/visuallyHidden parsed: 0B(0.00%) gzip: 0B(0.00%)
@base-ui-components/utils/warn parsed: 0B(0.00%) gzip: 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against e330d42

@netlify

netlify Bot commented Sep 1, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit ff68fd8
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/68e3a62665a55b0008ebd04e
😎 Deploy Preview https://deploy-preview-2604--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.

@mui-bot

mui-bot commented Sep 3, 2025 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui-components/react ▼-20B(-0.01%) 🔺+3B(0.00%)

Details of bundle changes

@mnajdova
mnajdova marked this pull request as ready for review September 3, 2025 13:27
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Sep 3, 2025

@atomiks atomiks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks solid, though I wonder what happens with Select's positioning if the disabled item is currently selected given it overlaps the trigger?

@oliviertassinari oliviertassinari added the component: menu Changes related to the menu component. label Sep 24, 2025
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 6, 2025
@mnajdova

mnajdova commented Oct 6, 2025

Copy link
Copy Markdown
Member Author

Change looks solid, though I wonder what happens with Select's positioning if the disabled item is currently selected given it overlaps the trigger?

@atomiks if the selected item is first and disabled it focuses it. Otherwise it finds the first non-disabled item if no item is preselected. I think this behavior makes sense. Here is a sandbox to test the behavior: https://codesandbox.io/p/devbox/wizardly-shannon-dq8svg?file=%2Fsrc%2FApp.tsx&workspaceId=ws_HE9JRzFW36Y2kpBoSwdvZ5

@mnajdova
mnajdova merged commit cea1eb8 into mui:master Oct 6, 2025
atomiks added a commit to atomiks/base-ui that referenced this pull request Jun 12, 2026
Remove the vestigial previousOnNavigateRef (onNavigate is a stable callback, so it always stored the same reference) and the stale comment describing the removed conditional-onNavigate behavior. Resolve the owner document from the in-DOM domReferenceElement instead of the provably-null floatingElement (realm-safe). Document the deliberate disabledIndices omission in initial focus (regression guard for mui#2604).
atomiks added a commit to atomiks/base-ui that referenced this pull request Jun 12, 2026
Remove the vestigial previousOnNavigateRef (onNavigate is a stable callback, so it always stored the same reference) and the stale comment describing the removed conditional-onNavigate behavior. Resolve the owner document from the in-DOM domReferenceElement instead of the provably-null floatingElement (realm-safe). Document the deliberate disabledIndices omission in initial focus (regression guard for mui#2604).
trueadm added a commit to octanejs/octane that referenced this pull request Jul 27, 2026
…3e) (#308)

* feat(base-ui): port TimeoutManager

First piece of Phase 3e (list navigation + typeahead), which lands together with
the Menu family so the navigation infrastructure has a real consumer rather than
sitting untested.

TimeoutManager holds several keyed timeouts behind one handle, so a caller can
start, replace and cancel each independently and drop them all on teardown. It is
distinct from `utils/useTimeout`'s `Timeout`, which owns exactly one. Pure, so it
is a straight transcription with no renderer adaptation.

No consumer yet — Menu's typeahead and submenu timing are what use it. Untested
on purpose rather than by omission: a differential test needs a rendered
component, and the first one arrives with Menu.

Co-Authored-By: Claude Opus 5 <[email protected]>

* feat(base-ui): port RequestQueue, getPseudoElementBounds, useMixedToggleClickHandler

Three more Phase 3e helpers, landing with the Menu family so the navigation
infrastructure has real consumers rather than sitting untested.

RequestQueue tracks each key's lifecycle through queued -> pending and caps
in-flight requests, with `pickEntries` as the subclass hook for ordering (FIFO by
default). getPseudoElementBounds widens an element's box to cover its
::before/::after, so hit-testing accounts for decorations drawn outside it; it
short-circuits under jsdom, where getComputedStyle with a pseudo-element is not
implemented. Both are pure, so they are straight transcriptions.

useMixedToggleClickHandler is a hook, so it follows the binding's plain-`.ts`
convention: the caller's slot arrives as the trailing argument via `splitSlot`
and the `useRef`/`useMemo` it composes take derived sub-slots. Its events are
native rather than synthetic, so the handlers take the native event and
`preventBaseUIHandler` is the shim `mergeProps` attaches. Upstream's empty
`UseMixedToggleClickHandlerState` interface is a docs-pipeline artifact with no
members and is dropped.

No consumers yet — Menu's trigger and submenu behavior are what use these.
Untested on purpose rather than by omission: a differential test needs a rendered
component, and the first one arrives with Menu.

Validation: `tsrx-tsc --noEmit` on @octanejs/base-ui and `pnpm format:check`,
both clean. No test run — these files have no consumer and no test yet.

Co-Authored-By: Claude Opus 5 <[email protected]>

* feat(base-ui): port useListNavigation

The largest piece of Phase 3e (list navigation + typeahead), which lands together
with the Menu family so the navigation infrastructure has a real consumer rather
than sitting untested.

useListNavigation adds arrow-key navigation over a list of items using either real
DOM focus or virtual focus (`aria-activedescendant`), and returns the
`{ reference, floating, item, trigger }` prop bags Menu, Select and Combobox merge
onto their parts. octane adaptations: it reads the FloatingRootStore
(`store.useState`/`select`/`setOpen`/`context`); events are native, so
`event.nativeEvent` collapses to `event`; `useIsoLayoutEffect` is octane's
`useLayoutEffect`, and because a plain-`.ts` hook is not compiled, an `undefined`
dep array runs the effect every render, matching upstream's dep-less form; every
composed hook threads an explicit sub-slot. The two dev-only `console.warn`
misconfiguration guards are dropped — this package carries no
`process.env.NODE_ENV` branches.

The `grid` option stays injected rather than imported, so non-grid consumers keep
the grid helpers out of their bundles. It is typed here as `GridNavigator`, which
the `gridNavigation` port satisfies structurally.

Porting this exposed that the vendored list-navigation helpers had drifted from
Base UI 1.6.0: `isListIndexDisabled` neither skipped invisible items nor kept the
attribute fallback separate from an explicit `disabledIndices`. useListNavigation
depends on that separation — it deliberately omits `disabledIndices` when choosing
the item to focus on open so attribute-disabled items are still skipped for
consumers passing an empty array (mui/base-ui#2604). `list-utils` now matches
upstream's body and signatures, and `useCompositeRoot` drops the `{ current }`
wrappers it needed for the old shape. That is a behavior fix for the already
shipped composite roving focus, so it carries a changeset.

No consumer yet — Menu is what uses this. Untested on purpose rather than by
omission: a differential test needs a rendered component, and the first one arrives
with Menu.

Validation: `tsrx-tsc --noEmit` clean, `vitest --project base-ui` 96/96 green,
prettier clean on the changed files.

Co-Authored-By: Claude Opus 5 <[email protected]>

* feat(base-ui): port grid navigation and useTypeahead

Ports three Base UI 1.6.0 sources for the list-navigation infrastructure:

- `floating-ui-react/hooks/gridNavigation.ts` -> `utils/floating/gridNavigation.ts`,
  the uniform 1x1 navigator `useListNavigation` injects for its own `grid` option.
- `internals/composite/root/gridNavigation.ts` -> `utils/composite/gridNavigation.ts`,
  the cell-map-backed navigator a composite passes to `useCompositeRoot`'s `grid`
  prop. Two different upstream files, kept separate.
- `floating-ui-react/hooks/useTypeahead.ts` -> `utils/floating/useTypeahead.ts`,
  native-event and slot-threaded like the other floating hooks.

Both navigators need the grid half of upstream's `floating-ui-react/utils/composite.ts`
(`getGridNavigatedIndex` and the cell-map helpers), which had no counterpart here;
it lands as `utils/composite/grid-utils.ts`, beside the list algebra this binding
already vendors into `list-utils.ts`. It depends on that module's Base UI 1.6.0
signatures, which arrive with `useListNavigation`.

No consumer until Menu lands, so no tests yet.

Co-Authored-By: Claude Opus 5 <[email protected]>

---------

Co-authored-by: Claude Opus 5 <[email protected]>
michaldudak added a commit to michaldudak/base-ui that referenced this pull request Aug 4, 2026
Opening a virtualized list with an arrow key scanned only the DOM for the
first enabled item, so the first unmounted slot was picked as enabled and
`isItemDisabled` was ignored. The initial-open scan now consults the consumer
predicate alongside the DOM state, keeping the attribute-based skipping that
mui#2604 relies on.

A disabled `<Combobox.Virtualizer>` stayed registered with the list, which
suppressed the DOM `scrollIntoView` that static lists rely on while the
virtualizer itself scrolled no rows. The registry entry now carries whether
virtualization is enabled, and DOM scrolling is only suppressed while it is.

Also list `Combobox.Virtualizer` in the anatomy.

Co-Authored-By: Claude Opus 5 <[email protected]>
arindampradhan added a commit to noevaresearch/base-ui that referenced this pull request Sep 9, 2026
…stNavigation (the indexRef truth mirror with the reactive activeIndex reconciliation, the focusItem scheduler over enqueueFocus + the animation-frame handle, the wait-for-list-populated microtask→rAF retry with the disabledIndices-omitted initial sync (mui#2604), the per-effect previous-open/mounted snapshots standing in for the shared refs the upstream no-deps effect writes, the keyboard modality mirrors, commonOnKeyDown's nested close key/Home/End/grid/main-axis matrix with allowEscape, the item bag's hover sync + stationary-WebKit guard + pointer-leave reset with focus-back, the floating bag's Shift+Tab close + pointer-modality tracker, the trigger bag's open-on-navigation and virtual-input checks, and the aria-activedescendant attribute riding a new lazily-resolved ElementHandlers::attributes bag) plus gridNavigation (the positional-arg shim with the 2-column default and the out-of-bounds→None sentinel) and utils/composite's grid half (findNonDisabledListIndex/getMin/MaxListIndex, the getGridNavigatedIndex matrix — DOM-row inference via closest('[role=row]'), the virtualized-gap uniform-grid walk, the vertical loop offset math, the horizontal row-clamp/loop arms with the rtl swap — and the createGridCellMap/getGridCellIndexOfCorner/getGridCellIndices cell-map trio) — REASONS.listNavigation/focusOut added, ElementHandlers gains onPointerMove/onPointerLeave slots; 27 host + 13 wasm tests mirroring the upstream suite (the 2x2 cell-map packing, the vertical loop offset math, the rtl clamp, opens/wraps/disabled-skip, hover+pointer-leave reset, virtualfocus bus, aria-activedescendant, Shift+Tab, nested close, openOnArrowKeyDown=false, the injected 2D grid) — 127 wasm + 114 host crate-wide, cargo test --workspace green
AndrewJSchoen added a commit to semio-ai/semio-ui that referenced this pull request Nov 10, 2026
… Base UI Menu

Every menu runs on Base UI's menu parts: Dropdown (and everything built on it,
ActionMenu included) on `menu`, row ContextMenu on `context-menu`, and
TooltipHost's canvas context menu and click popover on a `menu` root positioned
at the pointer through a virtual anchor. One item set (NestedItem, NestedCheckbox,
NestedRadio, NestedSelect, NestedCheckboxTree, NestedMenu, NestedLabel,
NestedStatic, NestedSeparator) serves all of them; NestedParent and its provider
and hook are deprecated no-ops.

Where Base UI follows the WAI-ARIA menu pattern and Radix did not, the menus
follow it:
- Tab in an open Dropdown closes it and moves on.
- Escape in a submenu closes only that submenu.
- Every disabled entry is keyboard-reachable, aria-disabled and inert.
- A Dropdown neither hides the page from assistive technology nor traps focus.

Where Base UI's default is not an accessibility choice, the Radix behaviour
stays:
- No wrap-around at either end (loopFocus={false} on roots and submenus).
- Modal menus: scroll locked, a press outside only closes the menu.
- Row and canvas context menus keep Tab and Shift+Tab inside the open menu.
  Base UI's list navigation closes a menu on Shift+Tab as a cancellable
  focus-out, which these menus cancel.
- A keyboard open focuses the first entry even when it is disabled. Base UI
  skips disabled entries on open (mui/base-ui#2604) while arrow keys reach them;
  APG places focus on the first item and keeps disabled items focusable.
- A ContextMenu opens to the right of the press point.
- A press in the notifications region does not dismiss a menu, and an open
  menu receives Escape before a toast.
- Triggers, popups and check items keep their data-state values.

Supporting changes:
- An Escape a disabled entry's reason tooltip dismissed does not also close the
  menu. Tooltip marks the Escape events it consumes; defaultPrevented cannot be
  the signal, because Base UI prevents the default of every key but Tab on a
  focused disabled item.
- Tooltip notes a press on a disabled trigger in the capture phase: Base UI
  does not run a disabled part's bubble-phase pointer and click handlers.
- A non-button wrapper trigger (`<span><MenuButton /></span>`) only relays
  events; it takes no button role or tab stop, and Escape returns focus to the
  control inside it. A Dropdown that closes with focus inside moves focus back
  before its popup unmounts, so a surrounding Modal never claims it.
- A selected item's action runs after Base UI's close completion and focus
  return; ActionMenu runs it synchronously inside the selection event so
  clipboard writes keep the browser's user activation.
- The mobile submenu disclosure is a menuitem in the arrow-key order and
  toggles once per activation. SelectTree parent checkboxes leave the tab order;
  Space on the parent row toggles it and Enter or ArrowRight opens its children.
- TreeNavRoot ignores key events from a menu portalled out of a row.
- Listing click exemptions match menu item roles instead of
  data-radix-collection-item.
- The single-open coordinator is removed; Base UI's outside-press handling
  closes one menu when another opens by pointer.
- Dropdown gains `nativeButton`, inferred from an intrinsic trigger.
- vitest pre-bundles the new @base-ui/react subpaths.

menu-decisions.browser.tsx asserts each of these behaviours directly. The menu
parity record's intended differences are named in the next commit.

Co-Authored-By: Codex (gpt-6.1-sol) <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility a11y component: menu Changes related to the menu component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants