Select
Picks one option from a list, with type-ahead and full keyboard support.
Use a select when people choose one option from a list of about 5 to 15. For two to five options that should all stay visible, use a radio group.
Used for due dates and reminders.
import { Select } from "@aloxe/react";
const timezones = [
{ value: "europe-lisbon", label: "Lisbon (UTC+0)" },
{ value: "europe-paris", label: "Paris (UTC+1)" },
{ value: "america-new-york", label: "New York (UTC−5)" },
{ value: "asia-tokyo", label: "Tokyo (UTC+9)" },
];
export default function SelectBasic() {
return (
<Select
label="Time zone"
name="timezone"
items={timezones}
placeholder="Choose a time zone"
description="Used for due dates and reminders."
className="w-full max-w-xs"
/>
);
}Installation
npm i @aloxe/react @aloxe/tokensThen add the CSS imports from Installation.
Usage
import { Select } from "@aloxe/react";
const roles = [
{ value: "viewer", label: "Viewer" },
{ value: "editor", label: "Editor" },
];
<Select label="Role" name="role" items={roles} placeholder="Choose a role" />Pass the options as items, objects with a value and a label. The trigger shows the selected option's label. For custom option content, pass SelectItem children as well as items.
The list opens in a popup attached to the page body. It copies the data-theme and data-brand of the place the select sits in, so it matches a themed panel.
Examples
States
A selected value, the error state with a placeholder, and a disabled select. Single options can be disabled with disabled: true in items.
Only owners can change roles.
import { Select } from "@aloxe/react";
const roles = [
{ value: "viewer", label: "Viewer" },
{ value: "editor", label: "Editor" },
{ value: "admin", label: "Admin" },
{ value: "owner", label: "Owner", disabled: true },
];
export default function SelectStates() {
return (
<div className="flex w-full max-w-xs flex-col gap-6">
<Select label="Role" items={roles} defaultValue="editor" />
<Select
label="Role"
items={roles}
placeholder="Choose a role"
error="Choose a role for this member."
/>
<Select
label="Role"
items={roles}
defaultValue="viewer"
disabled
description="Only owners can change roles."
/>
</div>
);
}Controlled
Pass value and onValueChange. The value type follows your items, so onValueChange gets a typed value.
Saved value: daily
"use client";
import { Select } from "@aloxe/react";
import { useState } from "react";
type Frequency = "instant" | "daily" | "weekly";
const options: { value: Frequency; label: string }[] = [
{ value: "instant", label: "As it happens" },
{ value: "daily", label: "Daily digest" },
{ value: "weekly", label: "Weekly digest" },
];
export default function SelectControlled() {
const [frequency, setFrequency] = useState<Frequency>("daily");
return (
<div className="flex w-full max-w-xs flex-col gap-2">
<Select<Frequency>
label="Email frequency"
items={options}
value={frequency}
onValueChange={(value) => {
if (value) setFrequency(value);
}}
/>
<p className="aloxe-text-body-sm text-ax-text-secondary">Saved value: {frequency}</p>
</div>
);
}Accessibility
| Key | Action |
|---|---|
| Enter, Space, Down or Up | Opens the list when the trigger has focus. |
| Down and Up | Moves through the options. |
| Home and End | Moves to the first or last option. |
| A letter | Jumps to the next option starting with it (type-ahead). |
| Enter or Space | Selects the highlighted option and closes the list. |
| Escape | Closes the list and returns focus to the trigger. |
| Tab | Closes the list and moves on. |
- Follows the WAI-ARIA listbox pattern: the trigger is a combobox that controls the popup listbox.
- The label names the trigger.
descriptionanderrorare linked witharia-describedby. - The selected option has a check mark as well as its highlight, so selection doesn't rely on colour.
API reference
Every part accepts className and renders a data-aloxe attribute you can target in CSS, such as [data-aloxe="select"].
Select
Extends Base UI Select.Root.
| Prop | Type | Default | Description |
|---|---|---|---|
| label (required) | ReactNode | The visible label and the trigger's accessible name. | |
| items | { value: Value; label: ReactNode; disabled?: boolean }[] | The options. The trigger shows the selected option's label. | |
| placeholder | ReactNode | Shown in the trigger while nothing is selected. | |
| value | Value | null | Controlled value. Pair with onValueChange. | |
| defaultValue | Value | null | Initial value when uncontrolled. | |
| onValueChange | (value: Value | null, details) => void | Called when the user picks an option. | |
| showLabel | boolean | true | false hides the label visually only. |
| description | ReactNode | Helper text under the trigger, linked with aria-describedby. | |
| error | ReactNode | Error message. Sets the error state and links the message to the trigger. | |
| disabled | boolean | false | Disables the select. |
| name | string | Form field name. The selected value is submitted with the form. | |
| required | boolean | false | Requires a value before the form submits. |
| children | ReactNode | SelectItem elements, for custom option content. Pass items too so the trigger can show labels. | |
| className | string | Classes for the wrapper (label, trigger and messages). |
SelectItem
Extends Base UI Select.Item.
| Prop | Type | Default | Description |
|---|---|---|---|
| value (required) | Value | The value this option selects. | |
| children | ReactNode | The option label, also used for type-ahead. | |
| disabled | boolean | false | Keeps the option visible but not selectable. |
| className | string | Merged with the default classes. |
Figma
Matches the Select component. Figma Label, Value and Helper map to label, the selected item and description; Show label maps to showLabel. The open list uses the Menu item style.
See Figma for where to get the file and how its names map to code.