Select
A native <select> with Fluent styling: a 1px border with an accessible bottom stroke, a token chevron at the inline end (replaceable through icon) and a primary bottom border while focused. Give it a name with a Field label, aria-label or aria-labelledby. Inside a Field it picks up the label, hint, error, required (native attribute) and invalid state automatically.
size resolves from its own prop, then the surrounding Field's size, then WaveProvider inputDefaults.size, else 'medium'; appearance from its own prop, then WaveProvider inputDefaults.appearance, else 'outline'; both render as data-size and data-appearance on the <select>.
Examples
Default
export const Default: Story = {
render: (args) => (
<Select {...args}>
<option value="">Select an option</option>
<option value="a">Option A</option>
<option value="b">Option B</option>
<option value="c">Option C</option>
</Select>
),
};Error
export const Error: Story = {
args: {
error: 'Please select a value',
},
render: (args) => (
<Select {...args}>
<option value="">Select an option</option>
<option value="a">Option A</option>
</Select>
),
};Disabled
export const Disabled: Story = {
args: {
disabled: true,
},
render: (args) => (
<Select {...args}>
<option value="">Disabled</option>
</Select>
),
};In Field
Where you live today.
export const InField: Story = {
args: {
'aria-label': undefined,
defaultValue: '',
},
render: (args) => (
<Field label="Country" hint="Where you live today." required>
<Select {...args}>
<option value="" disabled>
Choose a country
</option>
<option value="no">Norway</option>
<option value="se">Sweden</option>
</Select>
</Field>
),
};Sizes And Appearances
export const SizesAndAppearances: Story = {
render: (args) => (
<SizeAppearanceGrid
render={(size, appearance) => (
<Select {...args} size={size} appearance={appearance} aria-label={`${size} ${appearance}`}>
<option>Norway</option>
<option>Sweden</option>
</Select>
)}
/>
),
};Custom Icon
export const CustomIcon: Story = {
render: (args) => (
<div className="flex flex-col gap-3">
<Select
{...args}
aria-label="Sort by"
icon={
<svg viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.5">
<path d="M5 8l5 5 5-5" />
</svg>
}
>
<option>Name</option>
<option>Date</option>
</Select>
<Select {...args} aria-label="No chevron" icon={false}>
<option>Name</option>
<option>Date</option>
</Select>
</div>
),
};Controlled
export const Controlled: Story = {
render: function Render(args) {
const [value, setValue] = useState('a');
return (
<div className="flex flex-col gap-2">
<Select {...args} value={value} onValueChange={setValue}>
<option value="a">Option A</option>
<option value="b">Option B</option>
</Select>
<span className="text-wave-caption-1 text-wave-muted-foreground">Selected: {value}</span>
</div>
);
},
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
error | string | boolean | No | Validation error. The error border also shows whenever the select ends up | |
errorMessageProps | InputErrorMessageProps | No | Props of the error message element ( | |
size | 'small' | 'medium' | 'large' | No | Size of the field: | |
htmlSize | number | No | The native | |
appearance | 'outline' | 'underline' | 'filled-darker' | 'filled-lighter' | No | Look of the field: | |
icon | Slot<'span'> | No | the drawn chevron | The chevron at the inline end (Fluent UI's |
onValueChange | (value: string) => void | No | Called with the selected option's value on every change, next to the native | |
ref | React.Ref<HTMLSelectElement> | No | Ref to the |
Any other prop is passed to the element it renders (HTMLSelectElement).
Stable class names
| Part | Class |
|---|---|
root | wave-select |
errorMessage | wave-select__error-message |
wrapper | wave-select__wrapper |
icon | wave-select__icon |