Skip to content

[dialog][popover][drawer] Keep generated ids when id is undefined - #6343

Merged
flaviendelangle merged 2 commits into
mui:masterfrom
henryqdineen:hqd-popup-undefined-id
Nov 25, 2026
Merged

flaviendelangle merged 2 commits into
mui:masterfrom
henryqdineen:hqd-popup-undefined-id

Conversation

@henryqdineen

Copy link
Copy Markdown
Contributor

We hit this in a design system that wraps Base UI. Its components take optional per-part ids and forward them, so a dialog with no id passes id={undefined} to Dialog.Popup. Our Playwright tests find a dialog through its trigger's aria-controls, and on our default dialog the trigger didn't have one. Checking the other parts turned up the same problem in Popover and Drawer.

The caller's props merge last and mergeProps lets undefined win, so the generated id is erased:

function InfoPopover({ title, id }: { title: string; id?: { popup?: string; title?: string } }) {
  return (
    <Popover.Root>
      <Popover.Trigger>Info</Popover.Trigger>
      <Popover.Portal>
        <Popover.Positioner>
          <Popover.Popup id={id?.popup}>
            <Popover.Title id={id?.title}>{title}</Popover.Title>
          </Popover.Popup>
        </Popover.Positioner>
      </Popover.Portal>
    </Popover.Root>
  );
}
// <InfoPopover title="Billing" />, after opening:
// - the popup has no id, so the trigger has no aria-controls
// - the popup's aria-labelledby points at the title's generated id, but the <h2> has no id
  • Dialog.Popup (and AlertDialog), Popover.Popup, Drawer.Popup: no popup id, so no aria-controls.
  • Popover.Title, Popover.Description: the popup's aria-labelledby or aria-describedby points at an id no element has.

Menu.Popup, Dialog.Title, Dialog.Description and the triggers already treat id={undefined} like an omitted id, and Radix recently made the same change for its Dialog in radix-ui/primitives#4210. This PR does the same in Dialog.Popup, Popover.Popup, Drawer.Popup, Popover.Title and Popover.Description: take id out of the props and fall back to the generated id. mergeProps is unchanged, so undefined still wins for other props (aria-labelledby={undefined} still drops the automatic label).

Tests: each part gets an id={undefined} case that fails without the fix in jsdom and Chromium, plus custom-id cases for Popover.Title, Popover.Description and Drawer.Popup, which had none.

Not fixed here, same pattern: Select.Popup/Select.List, Combobox.List/Combobox.Popup, and probably Drawer.SwipeArea. That's why the popup tests are per file rather than in popupConformanceTests, where they'd also fail for Select and Combobox. Happy to follow up.

🤖 Generated with Claude Code

…fined

Dialog.Popup (also used by AlertDialog), Popover.Popup and Drawer.Popup
put the generated id in their internal props and merged elementProps
after it, so an explicit id={undefined} (common when a wrapper forwards
an optional id) left the popup without an id and the open trigger
without aria-controls. Drawer.Popup already computed
elementProps.id ?? defaultPopupId but the spread undid it. Take id out
of the props and use idProp ?? defaultPopupId, as Menu.Popup and the
triggers already treat an undefined id like an omitted one.
…efined

Popover.Title and Popover.Description passed elementProps.id to
useBaseUiId but left id in elementProps, so an explicit id={undefined}
(common when a wrapper forwards an optional id) overrode the generated
id on the element while the store still held it. The popup's
aria-labelledby and aria-describedby then pointed at an id no element
had. Take id out of the props, as Dialog.Title and Dialog.Description
already do.
@pkg-pr-new

pkg-pr-new Bot commented Nov 24, 2026

Copy link
Copy Markdown

commit: 4adb4a4

@code-infra-dashboard

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

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+16B(0.00%) 🔺+23B(+0.01%)

Details of bundle changes

Performance

No regressions in 36 benchmarks · precise to ±8.5% (±17.9% at worst) · ran 3m 14s · details


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

@netlify

netlify Bot commented Nov 24, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

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

@flaviendelangle flaviendelangle added type: bug It doesn't behave as expected. component: drawer Changes related to the drawer component. component: dialog Changes related to the dialog component. component: popover Changes related to the popover component. labels Nov 25, 2026
@flaviendelangle
flaviendelangle merged commit 3091332 into mui:master Nov 25, 2026
24 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: dialog Changes related to the dialog component. component: drawer Changes related to the drawer component. component: popover Changes related to the popover component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants