[ButtonGroup][ToggleButtonGroup] Add optional roving focus keyboard navigation #46789
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.
…eyboard navigation (Arrow keys, Home/End); add tests and types
Problem: Toolbar-like groups aren’t fully accessible out of the box; the docs
DemoToolbar
usesuseToolbar
to enable Arrow/Home/End navigation but this isn’t available in shipped components.Approach: Add an opt-in
rovingFocus
prop toButtonGroup
andToggleButtonGroup
implementing roving focus keyboard navigation:ArrowLeft/Right (or Up/Down for vertical), with RTL-aware swapping
Home moves focus to first; End to last
No visual/UI regressions; pure behavior addition
Why this instead of moving docs
useToolbar
:Maintainer guidance suggested improving
ButtonGroup
/ToggleButtonGroup
Keeps the solution general, composable, and avoids coupling demo-only code into core
Backwards compatibility: Default behavior unchanged.
rovingFocus
is opt-in.Types: Added
rovingFocus?: boolean
toButtonGroupProps
andToggleButtonGroupProps
.Tests: Added focused tests to verify Arrow/Home/End behavior.
Docs: Prop will surface in API docs via existing generation pipeline.
Files changed (key)
packages/mui-material/src/ButtonGroup/ButtonGroup.js
: addrovingFocus
handling; RTL/orientation-aware keyboard navigation.packages/mui-material/src/ButtonGroup/ButtonGroup.d.ts
: addrovingFocus?: boolean
.packages/mui-material/src/ButtonGroup/ButtonGroup.test.js
: add roving focus test.packages/mui-material/src/ToggleButtonGroup/ToggleButtonGroup.js
: mirrorrovingFocus
behavior.packages/mui-material/src/ToggleButtonGroup/ToggleButtonGroup.d.ts
: addrovingFocus?: boolean
.packages/mui-material/src/ToggleButtonGroup/ToggleButtonGroup.test.js
: add roving focus test.How reviewers can test
If you want, I can push this branch to your fork and open the PR. Run:
mui/material-ui
master, paste the title and description above.