Skip to content

[checkbox][switch][radio] Prefer aria-label over associated labels - #5787

Merged
atomiks merged 3 commits into
mui:masterfrom
atomiks:claude/base-ui-issue-5786-bcce9c
Sep 25, 2026
Merged

atomiks merged 3 commits into
mui:masterfrom
atomiks:claude/base-ui-issue-5786-bcce9c

Conversation

@atomiks

@atomiks atomiks commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #5786

A Checkbox, Switch, or Radio with an aria-label inside a <label> (native or Field.Label) had its name announced twice, for example "lease.pdf lease.pdf".

The control got an aria-labelledby pointing at the label, which takes precedence over aria-label. But the label contains the control itself, so when the name is computed from the label's contents, the control's aria-label is read along with the label text.

This PR skips the generated aria-labelledby when the control has an aria-label, so the aria-label wins, like it does on native inputs. This covers both the Field.Label id and the wrapping/sibling <label> fallback. With a sibling <label htmlFor>, the label text used to replace the aria-label; the aria-label now wins there too. An explicit aria-labelledby still takes precedence, and controls without an aria-label are unchanged.

useAriaLabelledBy takes the aria-label as a new optional last parameter, since the hook is exported from @base-ui/react/internals/labelable-provider. OTPField uses the same hook but is left as is, because its group label is also shared with the first input.

@atomiks atomiks added type: bug It doesn't behave as expected. component: checkbox Changes related to the checkbox component. component: switch Changes related to the switch component. component: radio group Changes related to the radio group component. labels Sep 24, 2026
@atomiks
atomiks marked this pull request as ready for review September 24, 2026 07:26
@pkg-pr-new

pkg-pr-new Bot commented Sep 24, 2026 •

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

  • vite-css-base-ui-example

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

commit: c6f71f1

@code-infra-dashboard

code-infra-dashboard Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+78B(+0.02%) 🔺+34B(+0.02%)

Details of bundle changes

Performance

Total duration: 1,045.39 ms +135.84 ms(+14.9%) | Renders: 76 (+0) | Paint: 1,715.77 ms +209.44 ms(+13.9%)

Test Duration Renders
Tabs mount (200 instances) 219.60 ms 🔺+38.79 ms(+21.5%) 3 (+0)
Select open (500 options) 54.27 ms 🔺+13.36 ms(+32.6%) 14 (+0)
Dialog mount (300 instances) 27.44 ms 🔺+5.84 ms(+27.0%) 1 (+0)
Popover mount (300 instances) 40.89 ms +5.63 ms(+16.0%) 1 (+0)

11 tests within noise — details

Metric alarms

Test Metric Change
Tabs mount (200 instances) bench:paint 🔺 +53.16 ms
Select open (500 options) bench:paint 🔺 +22.87 ms
Select open (500 options) bench:paint#select-open 🔺 +22.87 ms
Dialog mount (300 instances) bench:paint 🔺 +15.76 ms
Popover mount (300 instances) bench:paint 🔺 +13.80 ms

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

@netlify

netlify Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit c6f71f1
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6ab6040f5ba8250008307487
😎 Deploy Preview https://deploy-preview-5787--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: checkbox Changes related to the checkbox component. component: radio group Changes related to the radio group component. component: switch Changes related to the switch component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[checkbox] useAriaLabelledBy fallback ignores aria-label so a labelled control inside a label is named twice (follow-up to #4122)

1 participant