Repository navigation
[select][combobox] Forward root id to visible form element - #3722
Conversation
commit: |
Bundle size report
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Test: @greptileai |
Greptile OverviewGreptile SummaryThis PR forwards the root Key Changes:
Critical Issue Found: Confidence Score: 2/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
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
|
4b10254 to
4a06607
Compare
LukasTy
left a comment
There was a problem hiding this comment.
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
selectcomponent. - 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?
|
@LukasTy yep it's strange, but I mentioned behavioral changes in the second paragraph (and linked #3723) A couple notable things change by default:
The recommended solution is to use |
|
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) |
It was updated separately in #3723
Will check |
4a06607 to
36097ad
Compare
36097ad to
442fb29
Compare
Signed-off-by: atomiks <[email protected]>
ccfad41 to
b8e2554
Compare
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 theidprop 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 specifynativeLabel={false}and render a<div>so hovering<Field.Label>doesn't trigger:hoveronTrigger, 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 howFieldworked for select triggers before.Fixes #3714.
Fixes #3727.