Skip to content

[accordion][combobox][dialog][field][fieldset][menu][meter][popover][progress][select][slider][tabs][toast] Register the rendered id of labels, titles, and descriptions - #6358

Merged
LukasTy merged 4 commits into
mui:masterfrom
LukasTy:rendered-id-labels
Nov 30, 2026

Conversation

@LukasTy

@LukasTy LukasTy commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

When a part gets its id from a render element (render={<div id="custom" />}), the DOM element has id="custom", but the part registered its generated id with the owner. The owner's aria-labelledby or aria-describedby then pointed to an id that no element has.

The parts now resolve their id with the existing resolveRenderedId helper (added in #5527), so the owner gets the id that the DOM element has. When the render element sets id={undefined}, the element has no id, and the owner gets no ARIA reference.

Fixed parts:

  • Accordion.Trigger (panel aria-labelledby)
  • Combobox.GroupLabel, Menu.GroupLabel, Select.GroupLabel (group aria-labelledby)
  • Combobox.Label, Select.Label (trigger aria-labelledby)
  • Dialog.Title, Dialog.Description, and the AlertDialog and Drawer parts that reuse them
  • Popover.Title, Popover.Description
  • Field.Label, Field.Description, Field.Error
  • Fieldset.Legend, Meter.Label, Progress.Label, Slider.Label
  • Tabs.Tab (panel aria-labelledby)
  • Toast.Title, Toast.Description

Notes:

  • useRegisteredLabelId and useLabel take the render prop. The three group labels use useRegisteredLabelId instead of a copy of its effect. The Dialog and Popover titles and descriptions also use it, so a part that unmounts or loses its id releases only its own id.
  • An explicit id="" no longer gives the owner aria-labelledby="" or aria-describedby="". Accordion.Trigger keeps its old behavior and uses the generated id.
  • Field.Label now uses its id prop. Before, it kept the first id that it registered and ignored a later id change.
  • The id={undefined} behavior from [dialog][popover][drawer] Keep generated ids when id is undefined #6343 does not change: the part keeps its generated id.
  • Popup ids that triggers reference with aria-controls are not in this PR.

This lets Material UI remove the Menu2GroupLabel workaround from mui/material-ui#48823.

Generated with Claude Code

A part that gets its id from a `render` element now registers that id
with its owner, so `aria-labelledby` and `aria-describedby` point to an
element that exists. When the render element removes the id, the owner
gets no reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LukasTy LukasTy added component: select Changes related to the select component. component: menu Changes related to the menu component. component: alert dialog Changes related to the alert dialog component. component: tabs Changes related to the tabs component. component: slider Changes related to the slider component. type: bug It doesn't behave as expected. component: drawer Changes related to the drawer component. component: accordion Changes related to the accordion component. component: dialog Changes related to the dialog component. accessibility a11y component: popover Changes related to the popover component. component: toast Changes related to the toast component. component: progress Changes related to the progress component. component: field Changes related to the field component. component: meter Changes related to the meter component. component: combobox Changes related to the combobox component. component: fieldset labels Nov 26, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 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@6358
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@6358
    

commit: 9df8b07

@code-infra-dashboard

code-infra-dashboard Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react ▼-81B(-0.02%) 🔺+25B(+0.01%)

Details of bundle changes

Performance

No regressions in 36 benchmarks · precise to ±10.3% (±19.9% at worst) · ran 3m 54s · details


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

@netlify

netlify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 9df8b07
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6b0d690ba77ee3c6a79dd9de
😎 Deploy Preview https://deploy-preview-6358--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.

LukasTy and others added 2 commits November 27, 2026 15:39
- Field.Error resolves the render id only while mounted, so a pending lazy render element does not suspend the field.
- An id-less label or toast part releases only its own id and does not clear the id of another part.
- Field.Label uses its id prop, not the id that it registered before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Dialog.Title, Dialog.Description, Popover.Title, and Popover.Description now register their id through useRegisteredLabelId. An older part that loses its id or unmounts no longer clears the id of a newer part.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LukasTy

LukasTy commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

GPT Astra 6.2 review

I would approve this head. No remaining code findings in the documented component configurations.

All eight new Dialog and Popover regression tests failed on the preceding commit a1950bd and passed on 14df40e. They cover retaining the newer accessible name or description when an older part removes its ID or unmounts. The earlier Field.Error, Field.Label, Select.GroupLabel and Toast.Title reproductions also pass. The two-trigger Accordion case still reproduces outside the documented one-trigger-per-item configuration.

@LukasTy
LukasTy marked this pull request as ready for review November 27, 2026 14:25

@michaldudak michaldudak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The registered id matches the DOM id in every changed part. Two non-blocking nits:

1. 🟡 Field.Label stops labelling the control after a sibling label unmounts

packages/react/src/field/label/FieldLabel.tsx:41

const labelProps = useLabel({
  id: idProp, // before: labelId ?? idProp
  render,
  native: nativeLabel,
});

On master, Field.Label took its id from the context labelId, so when another label released its id, the surviving label re-rendered with a new id and registered again. Now its id no longer depends on context, so the registration effect never re-runs after the last-registered label unmounts.

<Field.Root>
  <Field.Label id="a">A</Field.Label>
  {second && <Field.Label id="b">B</Field.Label>}
  <Field.Control />
</Field.Root>
State master this PR
Both labels mounted aria-labelledby="b", both labels have id="b" aria-labelledby="b", labels have a and b
After second becomes false aria-labelledby="a" no aria-labelledby

It needs two label parts in one Field.Root with the last-registered one unmounting, so it is narrow, and master's duplicate id in the same setup was wrong too. A native <label htmlFor> still names a native control, so it only matters for nativeLabel={false} labels and controls named through aria-labelledby. The same applies to a Field.Label next to a Select.Label, Combobox.Label or Slider.Label in one field.

Either register again when the context labelId becomes undefined while the label still has an id, or accept "last label wins, no fallback" as Meter, Progress and Fieldset already do.

2. 🟡 Four copies of the same store setter adapter

packages/react/src/dialog/title/DialogTitle.tsx:23 (also DialogDescription.tsx, PopoverTitle.tsx, PopoverDescription.tsx)

const setTitleId = useStableCallback((action: React.SetStateAction<string | undefined>) => {
  store.set(
    'titleElementId',
    typeof action === 'function' ? action(store.state.titleElementId) : action,
  );
});
const id = useRegisteredLabelId(componentProps, setTitleId);

Each of the four parts adds a useStableCallback and an identical updater shim that differs only in the store key; Combobox.Label and Select.Label carry the same shim for labelId. A shared helper that takes the store and key would cover all of them. If two titles or descriptions in one popup are not worth supporting, store.useSyncedValueWithCleanup('titleElementId', id) with the resolved id is smaller and already handles the id-less case.

Dialog and Popover titles and descriptions, Select.Label, and
Combobox.Label each had a copy of the same updater shim. The new
useStoreIdSetter helper replaces all six copies.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LukasTy

LukasTy commented Nov 30, 2026

Copy link
Copy Markdown
Member Author
  1. I kept "last label wins, no fallback", so all label parts work the same way. A fallback only in useLabel would make the LabelableContext labels the exception. A real fallback needs a list of live ids in each owner: Field, Dialog, Popover, Select, Combobox, Meter, Progress, Fieldset, the group labels, and Toast. I can do that in a separate PR if you want, or let's wait until a real use case appears. Also, the fallback on master gave both labels the same DOM id.
  2. Done in 9df8b07. The new useStoreIdSetter(store, key) helper replaces the six copies in the Dialog and Popover titles and descriptions, Select.Label, and Combobox.Label. I kept the support for two titles or descriptions from the earlier review.

@LukasTy
LukasTy merged commit 0001791 into mui:master Nov 30, 2026
22 checks passed
@LukasTy
LukasTy deleted the rendered-id-labels branch November 30, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility a11y component: accordion Changes related to the accordion component. component: alert dialog Changes related to the alert dialog component. component: combobox Changes related to the combobox component. component: dialog Changes related to the dialog component. component: drawer Changes related to the drawer component. component: field Changes related to the field component. component: fieldset component: menu Changes related to the menu component. component: meter Changes related to the meter component. component: popover Changes related to the popover component. component: progress Changes related to the progress component. component: select Changes related to the select component. component: slider Changes related to the slider component. component: tabs Changes related to the tabs component. component: toast Changes related to the toast component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants