Skip to content

[select][combobox] Forward root id to visible form element - #3722

Merged
atomiks merged 6 commits into
mui:masterfrom
atomiks:fix/select-id-loc
Jan 15, 2026
Merged

atomiks merged 6 commits into
mui:masterfrom
atomiks:fix/select-id-loc

Conversation

@atomiks

@atomiks atomiks commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor

When the hidden input is focused on iOS, the software keyboard briefly opens despite focus relocating to the button. This can cause the page to scroll a bit when first tapping. Since <Combobox.Trigger> and <Select.Trigger> now render a <button>, it's a form control and should accept the id prop from the root instead of the hidden <input>.

There's a behavioral change when using <Field.Label> here. In another PR, I've added the ability to specify nativeLabel={false} and render a <div> so hovering <Field.Label> doesn't trigger :hover on Trigger, along with clicking the label not opening the popup (the native <select> only gets focused, not opened). Other libraries label select triggers this way (that is, they avoid <label>). This change makes <Field.Label> act like native <label> for the Select component, which is more expected and makes this technically a bug fix rather than a breaking change, though it's ambiguous because it does visibly affect how Field worked for select triggers before.

Fixes #3714.
Fixes #3727.

@atomiks atomiks added component: select Changes related to the select component. type: bug It doesn't behave as expected. component: combobox Changes related to the combobox component. labels Jan 12, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jan 12, 2026 •

Copy link
Copy Markdown
  • vite-css-base-ui-example

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

commit: b8e2554

@mui-bot

mui-bot commented Jan 12, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+142B(+0.03%) 🔺+100B(+0.07%)

Details of bundle changes


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

@netlify

netlify Bot commented Jan 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit b8e2554
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/696864fc6e7311000843eab5
😎 Deploy Preview https://deploy-preview-3722--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@atomiks
atomiks marked this pull request as ready for review January 12, 2026 04:11
@Janpot

Janpot commented Jan 12, 2026

Copy link
Copy Markdown
Member

Test: @greptileai

@Janpot Janpot removed the greptile label Jan 12, 2026
@greptile-apps

greptile-apps Bot commented Jan 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR forwards the root id prop to visible form elements (trigger button or input) instead of the hidden input, fixing an iOS keyboard issue and improving accessibility. The changes correctly handle two combobox modes: input outside popup (ID on input) and input inside popup (ID on trigger).

Key Changes:

  • Select: ID now forwarded to SelectTrigger (button element)
  • Combobox: ID conditionally forwarded to either ComboboxInput (standard) or ComboboxTrigger (input-inside-popup mode)
  • Hidden inputs: ID removed from hidden inputs (appropriate since they're aria-hidden)
  • Field.Label behavior: Now correctly links to visible form controls, matching native <label> behavior

Critical Issue Found:
The SelectRoot.tsx has a logic bug where triggerId is calculated separately from generatedId, causing the trigger to not receive an auto-generated ID when neither explicit id nor controlId are provided. This breaks accessibility and label association in standalone usage.

Confidence Score: 2/5

  • This PR contains a critical logic bug that will break ID generation for Select components in common usage scenarios
  • While the overall architectural approach is sound and the Combobox implementation is correct, the Select component has a critical bug where auto-generated IDs aren't applied to the trigger element. This will break accessibility, label association, and form field tracking when Select is used without an explicit id prop and without a Field.Root parent - a common standalone usage pattern.
  • packages/react/src/select/root/SelectRoot.tsx requires immediate attention to fix the triggerId calculation bug

Important Files Changed

File Analysis

Filename Score Overview
packages/react/src/select/root/SelectRoot.tsx 2/5 Forwards root ID to trigger element but has a logic bug where auto-generated IDs aren't applied when no explicit id/controlId is provided
packages/react/src/combobox/input/ComboboxInput.tsx 5/5 Correctly forwards root ID to input when outside popup, uses generated ID when inside popup - logic is sound
packages/react/src/combobox/trigger/ComboboxTrigger.tsx 5/5 Forwards root ID to trigger when input is inside popup, correctly implements conditional ID assignment

Sequence Diagram

sequenceDiagram
    participant User as User/Browser
    participant Label as Field.Label
    participant Root as Select/Combobox.Root
    participant Trigger as Trigger (Button)
    participant HiddenInput as Hidden Input
    participant Input as Combobox.Input

    Note over Root: PR Changes: Forward ID to visible form controls

    alt Select Component
        Root->>Root: useLabelableId() generates/uses ID
        Root->>Trigger: Forwards ID via mergedTriggerProps
        Root->>HiddenInput: No ID (removed in PR)
        User->>Label: Clicks label
        Label->>Trigger: Focuses trigger (via for attribute)
        Trigger->>Trigger: Opens popup
    end

    alt Combobox: Input Outside Popup
        Root->>Root: useLabelableId() generates/uses ID
        Root->>Input: Forwards rootId when !isInsidePopup
        Root->>HiddenInput: No ID (removed in PR)
        User->>Label: Clicks label
        Label->>Input: Focuses input (via for attribute)
    end

    alt Combobox: Input Inside Popup
        Root->>Root: useLabelableId() generates/uses ID
        Root->>Trigger: Forwards rootId when inputInsidePopup
        Root->>Input: Uses generated ID (not rootId)
        Root->>HiddenInput: No ID (removed in PR)
        User->>Label: Clicks label
        Label->>Trigger: Focuses trigger (via for attribute)
        Trigger->>Trigger: Opens popup
    end

    Note over Root,Input: Visible form controls now receive IDs<br/>for proper label association and accessibility
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@atomiks
atomiks force-pushed the fix/select-id-loc branch 2 times, most recently from 4b10254 to 4a06607 Compare January 12, 2026 08:59

@LukasTy LukasTy 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 resulting behavior looks slightly strange as it doesn't correlate with how native select approaches function.

  • Hovering a label on the desktop does not produce any visual feedback.
  • Clicking a label on the desktop focuses the native select component.
  • Clicking a label on mobile (iOS) opens the native select

This current approach mimics the mobile behavior on desktop, which I'm not sure is the best approach. 🤔
What are your thoughts on this?

@atomiks

atomiks commented Jan 12, 2026 •

Copy link
Copy Markdown
Contributor Author

@LukasTy yep it's strange, but I mentioned behavioral changes in the second paragraph (and linked #3723)

A couple notable things change by default:

  1. Hovering <label> triggers :hover on <button>s, which is consistent with native behavior (even though it's undesirable)
  2. Clicking the label opens the select popup, which doesn't match native behavior (on desktop at least... I'm not sure if we should try to differentiate between platforms like iOS). However, this also matches a native <label> implementation with our select. And trying to workaround this was really hard when I tried to fix it internally.

The recommended solution is to use nativeLabel={false} + render={<div />} on <Field.Label>, which I've done in the linked PR (#3727) separately, so it bypasses these <label> behaviors while still focusing the trigger while clicking (plus fixing the linked iOS issue of course)

@michaldudak

Copy link
Copy Markdown
Member

The "Labelling a Select" section in the docs is now outdated, isn't it?

Also, the behavior seems to be broken when I explicitly specify a trigger id (https://codesandbox.io/p/sandbox/hero---base-ui-example-forked-wgtc9k?file=%2Fsrc%2FApp.tsx%3A20%2C62)

@atomiks

atomiks commented Jan 14, 2026

Copy link
Copy Markdown
Contributor Author

The "Labelling a Select" section in the docs is now outdated, isn't it?

It was updated separately in #3723

Also, the behavior seems to be broken when I explicitly specify a trigger id

Will check

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jan 14, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jan 14, 2026
@atomiks
atomiks merged commit 4267d72 into mui:master Jan 15, 2026
@atomiks
atomiks deleted the fix/select-id-loc branch January 15, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: combobox Changes related to the combobox component. component: select Changes related to the select component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[combobox] label doesnt open combox if search is in menu [select] Page jumping on label tap on iOS

5 participants