feat: add NativeSelect component#12
Conversation
A native HTML select element styled to match the Kumo design system. Use when you need native OS behavior (especially on mobile) or browser autofill support via the autoComplete attribute. Features: - Visually matches the Select component trigger - Size variants: xs, sm, base, lg - Field wrapper support with label, description, error - Full support for browser autofill (autoComplete attribute) - Documentation and demos
In theory, this should work with Base UI Select (and Material UI Select) using a hidden input. If it doesn't work anymore, we should probably restore it. |
|
@oliviertassinari oh cool! I'd love to see a reference implementation to make sure I'm not just holding it wrong |
|
@oliviertassinari merci! I will take a look at our Select implementation and see where we may have drifted. |
|
@oliviertassinari I set up a fresh test with <Select.Root name="country" value={country} onValueChange={setCountry}>
<Select.Trigger>
<Select.Value placeholder="Select a country" />
</Select.Trigger>
<Select.Portal>
<Select.Positioner>
<Select.Popup>
<Select.Item value="US">United States</Select.Item>
<Select.Item value="CA">Canada</Select.Item>
...
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>The hidden input renders as: <input name="country" value="" tabindex="-1" aria-hidden="true" style="...">I placed this alongside a native I believe the issue is that the hidden input is missing the autocomplete attribute. The name attribute identifies the field for form submission, but browsers need autocomplete="country" to know what data to fill. The test at SelectRoot.test.tsx#L561 (https://github.com/mui/base-ui/blob/65c2d3ae03442fc69b042f3f92bbe4fd873e083b/packages/react/src/select/root/SelectRoot.test.tsx#L561) confirms the Select handles autofill events (via fireEvent.change), but without the autocomplete attribute, browsers don't trigger those events in the first place. Would you be open to adding an |
|
Implemented in mui/base-ui#4005 as a conversation starter, assuming I haven't misdiagnosed the issue here. |
|
Superseded by mui/base-ui#4005 and a forthcoming PR to bump Base UI version and consume this change. |
Summary
Adds a
NativeSelectcomponent - a native HTML<select>element styled to match the Kumo design system.Motivation
While Kumo's
Selectcomponent provides a fully customizable dropdown experience, there are scenarios where native browser behavior is preferable:Features
Selecttrigger when closedxs,sm,base(default),lg- matching other form controlslabel,description,error,labelTooltipprops for automatic Field wrapping with proper accessibility associationsrequired={false}to show "(optional)" badgeautoCompleteattribute for address, payment, and other standard form fieldsUsage
When to use NativeSelect vs Select
Checklist
xs,sm,base,lg)