[ButtonBase] Add theme.focusRing for keyboard focus ring#48647
Draft
siriwatknp wants to merge 2 commits into
Draft
[ButtonBase] Add theme.focusRing for keyboard focus ring#48647siriwatknp wants to merge 2 commits into
siriwatknp wants to merge 2 commits into
Conversation
Render an outline focus ring on Mui-focusVisible: - auto fallback when disableRipple removes the ripple focus indicator - opt-in via theme.focusRing (outline CSSProperties), ripple-independent - theme.focusRing: false hard-disables the ring Experiment: design in CONTEXT.md + docs/adr, demo at docs/pages/experiments/focus-ring.tsx.
Deploy previewhttps://deploy-preview-48647--material-ui.netlify.app/ Bundle size
Check out the code infra dashboard for more information about this PR. |
Member
|
I kind of needed a focus ring in #48613 already and added it when |
1 task
mj12albert
reviewed
Jun 18, 2026
| }); | ||
| } | ||
|
|
||
| // focusRing theme key |
Member
There was a problem hiding this comment.
Is "focus ring" the best name for this? Alternatives could be "focus outline" or "focus indicator"
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.
Preview: https://deploy-preview-48647--material-ui.netlify.app/experiments/focus-ring/
Experiment
Adds a keyboard focus ring to
ButtonBase(and its derived components), rendered with CSSoutlineonMui-focusVisible.Two behaviors, one renderer
disableRippleis set, the ripple — the only keyboard-focus indicator for ripple-pulse components (Button, IconButton, Fab, Tab…) — disappears, failing WCAG 2.4.7. The ring fills that gap automatically, no config needed. DefaultoutlineColor: palette.primary.main,outlineWidth: 2,outlineOffset: 2,outlineStyle: solid.theme.focusRingshows the ring on every keyboard focus, regardless of ripple. Typed as the outline subset ofReact.CSSProperties(outlineColor/outlineWidth/outlineOffset/outlineStyle) and spread directly onto the focus-visible styles — no field mapping.theme.focusRing: falsedisables the ring entirely, including the fallback.Why
outlineSurvives Windows High Contrast /
forced-colors(wherebox-shadowand background tints are stripped), has zero layout shift, and avoids colliding with thebox-shadowelevation Button/Fab already animate on focus. Seedocs/adr/0001.Demo
docs/pages/experiments/focus-ring.tsx— fallback / opt-in / kill-switch side by side. Tab through with the keyboard (ring isMui-focusVisible-only).Notes / open questions
disableRipplegain a visible focus outline — intended, but worth release-notes.ButtonBase+ derived only; other focusable components (TextField, Checkbox…) are out of scope here.CONTEXT.md+docs/adr/(included for review; can be dropped before merge).Draft — opening for discussion on the API shape and default color.