Select
Picks a single value from a list of options. The value is the value of the chosen SelectItem, and editors can clear it unless the field is required.
import {Select, SelectItem} from 'alinea/components'
export function SelectExample() {
return (
<Select label="Status" defaultValue="published" style={{width: 260}}>
<SelectItem value="draft">Draft</SelectItem>
<SelectItem value="published">Published</SelectItem>
<SelectItem value="archived">Archived</SelectItem>
</Select>
)
}Groups
Group related options under a label and divide groups with SelectSeparator. Items can show an icon and a description below their label.
import {
Select,
SelectGroup,
SelectItem,
SelectSeparator
} from 'alinea/components'
import {
IcRoundDescription,
IcRoundFeed,
IcRoundImage
} from 'alinea/dashboard/icons'
export function SelectGroupsExample() {
return (
<Select label="Entry type" defaultValue="product" style={{width: 280}}>
<SelectGroup label="Pages">
<SelectItem value="page" icon={IcRoundDescription}>
Page
</SelectItem>
<SelectItem
value="product"
icon={IcRoundImage}
description="A product with price and photos"
>
Product
</SelectItem>
</SelectGroup>
<SelectSeparator />
<SelectGroup label="Blog">
<SelectItem value="post" icon={IcRoundFeed}>
Blog post
</SelectItem>
</SelectGroup>
</Select>
)
}States
A placeholder shows while nothing is selected. Like the other form controls, a select takes description, error, required, disabled and readOnly.
import {Select, SelectItem} from 'alinea/components'
export function SelectStatesExample() {
return (
<div style={{display: 'grid', gap: 16, width: 280}}>
<Select label="Category" placeholder="Choose a category">
<SelectItem value="bedroom">Bedroom</SelectItem>
<SelectItem value="dining">Dining</SelectItem>
</Select>
<Select label="Locale" defaultValue="en" disabled>
<SelectItem value="en">English</SelectItem>
<SelectItem value="nl">Nederlands</SelectItem>
</Select>
<Select label="Status" required error="Pick a status to continue">
<SelectItem value="draft">Draft</SelectItem>
<SelectItem value="published">Published</SelectItem>
</Select>
</div>
)
}Props
<Select>
A labelled field to pick a single value from a list. The value can be cleared unless the field is required.
Also accepts className and style, id and aria-* labelling attributes and data-* attributes.
<SelectItem>
Also accepts className and style.
<SelectGroup>
Also accepts id and aria-* labelling attributes.
<SelectSeparator>
Accessibility
The list opens with Enter, Space or the arrow keys and supports typeahead: typing jumps to the first matching option. The options are announced as a listbox with the selected one marked.