[ButtonBase] Add focusableWhenDisabled prop#48680
Closed
siriwatknp wants to merge 3 commits into
Closed
Conversation
Make the internal focusableWhenDisabled prop public on ButtonBase, Button, and IconButton, and wire it through to useButtonBase (it was destructured but never forwarded). When set, the element uses aria-disabled instead of the native disabled attribute and keeps pointer-events, so a disabled element stays focusable and keeps firing events. This lets Tooltip listen to hover and focus directly on a disabled element and forward the accessible name to it, removing the need for the span wrapper that broke accessibility. Update the Tooltip disabled-elements docs accordingly.
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
Member
Author
|
@mj12albert Is this the plan when you added the |
Signed-off-by: Siriwat K <siriwatkunaporn@gmail.com>
Member
|
@siriwatknp I already have a PR open #48613 😬 |
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.
closes #33182
Sandbox: https://stackblitz.com/edit/o5kyiyjo?file=src%2FDemo.tsx
Problem
The documented way to use
Tooltipwith a disabled element wraps it in a<span>:Tooltipinjects the accessible name onto the outermost cloned child — thespan, not the button. This:aria-labelon aspan(Axe/Lighthouse warn — aspanhas no nameable role),<button>with no accessible name,aria-labelon the button) produces two elements with the same name, which breaksgetByLabelTextand risks double announcement.The wrapper is only needed because a disabled element doesn't fire the events
Tooltiplistens to — andButtonBaseadditionally setspointer-events: noneon.Mui-disabled.Solution
Make
focusableWhenDisableda public prop onButtonBase(inherited byButtonandIconButton). When set on a disabled element, it usesaria-disabledinstead of the nativedisabledattribute and keepspointer-events, so the element stays focusable and keeps firing events while remaining inert.Tooltipthen attaches directly to the element — works on hover and keyboard focus, and the accessible name lands on the element itself, no wrapper:Changes
ButtonBase: exposefocusableWhenDisabledpublicly (type + propType) and forward it touseButtonBase— it was previously destructured but never passed, so thedisabled→aria-disabledswap was dead code for component consumers.ButtonBase: move.Mui-disabled { pointer-events: none }into a variant gated on!focusableWhenDisabled, so a focusable-disabled element still receives hover events.focusableWhenDisabled; keep thespanapproach as the documented fallback for native / non-ButtonBaseelements.When
focusableWhenDisabledis falsy,ButtonBaseanduseButtonBasebehave exactly as before — only opt-in usage changes.