Select
A common form component for choosing a predefined value in a dropdown menu.
import { For } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Select } from 'base-ui-solid/select';
import styles from './index.module.css';
const apples = [
{ label: 'Gala', value: 'gala' },
{ label: 'Fuji', value: 'fuji' },
{ label: 'Honeycrisp', value: 'honeycrisp' },
{ label: 'Granny Smith', value: 'granny-smith' },
{ label: 'Pink Lady', value: 'pink-lady' },
];
export default function ExampleSelect() {
return (
<div class={styles.Field}>
<Select.Root items={apples}>
<Select.Label class={styles.Label}>Apple</Select.Label>
<Select.Trigger class={styles.Select}>
<Select.Value class={styles.Value} placeholder="Select apple" />
<Select.Icon>
<CaretUpDownIcon />
</Select.Icon>
</Select.Trigger>
<Select.Portal>
<Select.Positioner class={styles.Positioner} sideOffset={4}>
<Select.Popup class={styles.Popup}>
<Select.ScrollUpArrow class={styles.ScrollArrow}>
<CaretUpIcon />
</Select.ScrollUpArrow>
<Select.List class={styles.List}>
<For each={apples}>
{({ label, value }) => (
<Select.Item value={value} class={styles.Item}>
<Select.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Select.ItemIndicator>
<Select.ItemText class={styles.ItemText}>{label}</Select.ItemText>
</Select.Item>
)}
</For>
</Select.List>
<Select.ScrollDownArrow class={styles.ScrollArrow}>
<CaretDownIcon />
</Select.ScrollDownArrow>
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>
</div>
);
}
function CaretUpDownIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & { style?: JSX.CSSProperties },
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="M11 10H5l3 3.5zm0-4H5l3-3.5z" />
</svg>
);
}
function CheckIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & { style?: JSX.CSSProperties },
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="m2.5 8.5 4 4 7-9" />
</svg>
);
}
function CaretUpIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & { style?: JSX.CSSProperties },
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="M12 10H4l4-4.5z" />
</svg>
);
}
function CaretDownIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & { style?: JSX.CSSProperties },
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="M12 6H4l4 4.5z" />
</svg>
);
}
Usage guidelines
- Prefer Combobox for large lists: Select is not filterable, aside from basic keyboard typeahead functionality to find items by focusing and highlighting them. Prefer Combobox instead of Select when the number of items is sufficiently large to warrant filtering.
- Special positioning behavior: The select popup by default overlaps its trigger so the selected item’s text is aligned with the trigger’s value text. This behavior can be disabled or customized.
- Form controls must have an accessible name: Prefer
<Select.Label>, or provide anaria-labelon<Select.Trigger>when no visible label is rendered. See Labeling a select and the forms guide. - Closing animations: The popup stays rendered until its closing animation finishes. See JavaScript animations for animating it with Motion and for manual control.
Anatomy
Import the component and assemble its parts:
import { Select } from 'base-ui-solid/select';
<Select.Root>
<Select.Label />
<Select.Trigger>
<Select.Value />
<Select.Icon />
</Select.Trigger>
<Select.Portal>
<Select.Backdrop />
<Select.Positioner>
<Select.Popup>
<Select.ScrollUpArrow />
<Select.Arrow />
<Select.List>
<Select.Item>
<Select.ItemText />
<Select.ItemIndicator />
</Select.Item>
<Select.Separator />
<Select.Group>
<Select.GroupLabel />
</Select.Group>
</Select.List>
<Select.ScrollDownArrow />
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>;
Positioning
<Select.Positioner> has a special prop called alignItemWithTrigger which causes the positioning to act differently by default from other Positioner components.
The prop makes the select popup overlap the trigger so the selected item’s text is aligned with the trigger’s value text.
For styling, data-side is "none" on the .Popup and .Positioner parts when the mode is active.
To prevent the select popup from overlapping its trigger, set the alignItemWithTrigger prop to false.
When set to true (its default) there are a few important points to note about its behavior:
- Interaction type dependent: For UX reasons, the
alignItemWithTriggerpositioning mode is disabled if touch was the pointer type used to open the popup. - Viewport space dependent: There must be enough space in the viewport to align the selected item’s text with the trigger’s value text without causing the popup to be too vertically small — otherwise, it falls back to the default positioning mode.
This can be customized by setting
min-heighton the<Select.Positioner>element; a smaller value will fallback less often. Additionally, the trigger must be at least 20px from the edges of the top and bottom of the viewport, or it will also fall back. - Other positioning props are ignored: Props like
sideoralignhave no effect unless the prop is set tofalseor when in fallback mode.
Examples
Typed wrapper component
The following example shows a typed wrapper around the Select component with correct type inference and type safety:
import type { JSX } from '@solidjs/web';
import { Select } from 'base-ui-solid/select';
export function MySelect<Value, Multiple extends boolean | undefined = false>(
props: Select.Root.Props<Value, Multiple>,
): JSX.Element {
return <Select.Root {...props}>{/* ... */}</Select.Root>;
}
Formatting the value
By default, the <Select.Value> component renders the raw value.
Passing the items prop to <Select.Root> instead renders the matching label for the rendered value:
const items = [
{ value: null, label: 'Select theme' },
{ value: 'system', label: 'System default' },
{ value: 'light', label: 'Light' },
{ value: 'dark', label: 'Dark' },
];
<Select.Root items={items}>
<Select.Value />
</Select.Root>;
A function can also be passed as the children prop of <Select.Value> to render a formatted value:
const items = {
monospace: 'Monospace',
serif: 'Serif',
'san-serif': 'Sans-serif',
};
<Select.Value>
{(value: keyof typeof items) => (
<span style={{ 'font-family': value }}>
{items[value]}
</span>
)}
</Select.Value>;
To avoid lookup, object values for each item can also be used.
Labeling a select
Use <Select.Label> to provide a visible label for the select trigger:
<Select.Root>
<Select.Label>Theme</Select.Label>
{/* ... */}
</Select.Root>
<Select.Label> renders a <div>, so clicking it focuses the select trigger without opening the popup.
Placeholder values
To show a placeholder value, use the placeholder prop on <Select.Value>:
const items = [
{ value: 'system', label: 'System default' },
{ value: 'light', label: 'Light' },
{ value: 'dark', label: 'Dark' },
];
<Select.Root items={items}>
<Select.Value placeholder="Select theme" />
</Select.Root>;
With placeholders, users cannot clear selected values using the select itself. If the select value should be clearable from the popup (instead of an external “reset” button), use a null item rendered in the list itself:
const items = [
{ value: null, label: 'Select theme' },
{ value: 'system', label: 'System default' },
{ value: 'light', label: 'Light' },
{ value: 'dark', label: 'Dark' },
];
<Select.Root items={items}>
<Select.Value />
</Select.Root>;
Multiple selection
Add the multiple prop to the <Select.Root> component to allow multiple selections.
import { For } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Select } from 'base-ui-solid/select';
import styles from './index.module.css';
const languages = {
javascript: 'JavaScript',
typescript: 'TypeScript',
python: 'Python',
java: 'Java',
csharp: 'C#',
php: 'PHP',
cpp: 'C++',
rust: 'Rust',
go: 'Go',
swift: 'Swift',
};
type Language = keyof typeof languages;
const values = Object.keys(languages) as Language[];
function renderValue(value: Language[]) {
if (value.length === 0) {
return 'Select languages';
}
const firstLanguage = languages[value[0]];
const additionalLanguages = value.length > 1 ? ` (+${value.length - 1} more)` : '';
return firstLanguage + additionalLanguages;
}
export default function MultiSelectExample() {
return (
<div class={styles.Field}>
<Select.Root multiple defaultValue={['javascript', 'typescript']}>
<Select.Label class={styles.Label}>Languages</Select.Label>
<Select.Trigger class={styles.Select}>
<Select.Value class={styles.Value}>{renderValue}</Select.Value>
<Select.Icon>
<CaretUpDownIcon />
</Select.Icon>
</Select.Trigger>
<Select.Portal>
<Select.Positioner class={styles.Positioner} sideOffset={4} alignItemWithTrigger={false}>
<Select.Popup class={styles.Popup}>
<For each={values}>
{(value) => (
<Select.Item value={value} class={styles.Item}>
<Select.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Select.ItemIndicator>
<Select.ItemText class={styles.ItemText}>{languages[value]}</Select.ItemText>
</Select.Item>
)}
</For>
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>
</div>
);
}
function CaretUpDownIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & { style?: JSX.CSSProperties },
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="M11 10H5l3 3.5zm0-4H5l3-3.5z" />
</svg>
);
}
function CheckIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & { style?: JSX.CSSProperties },
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="m2.5 8.5 4 4 7-9" />
</svg>
);
}
Object values
Select items can use objects as values instead of primitives.
This lets you access the full object in custom render functions, and can avoid needing to specify items for lookup.
import { For } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Select } from 'base-ui-solid/select';
import styles from './index.module.css';
export default function ObjectValueSelect() {
return (
<div class={styles.Field}>
<Select.Root defaultValue={shippingMethods[0]} itemToStringValue={(item) => item.id}>
<Select.Label class={styles.Label}>Shipping method</Select.Label>
<Select.Trigger class={styles.Select}>
<Select.Value>
{(method: ShippingMethod) => (
<span class={styles.ValueText}>
<span class={styles.ValuePrimary}>{method.name}</span>
<span class={styles.ValueSecondary}>
{method.duration} ({method.price})
</span>
</span>
)}
</Select.Value>
<Select.Icon>
<CaretUpDownIcon />
</Select.Icon>
</Select.Trigger>
<Select.Portal>
<Select.Positioner class={styles.Positioner} sideOffset={4}>
<Select.Popup class={styles.Popup}>
<Select.ScrollUpArrow class={styles.ScrollArrow}>
<CaretUpIcon />
</Select.ScrollUpArrow>
<Select.List class={styles.List}>
<For each={shippingMethods}>
{(method) => (
<Select.Item value={method} class={styles.Item}>
<Select.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Select.ItemIndicator>
<Select.ItemText class={styles.ItemText}>
<span class={styles.ItemLabel}>{method.name}</span>
<span class={styles.ItemDescription}>
{method.duration} ({method.price})
</span>
</Select.ItemText>
</Select.Item>
)}
</For>
</Select.List>
<Select.ScrollDownArrow class={styles.ScrollArrow}>
<CaretDownIcon />
</Select.ScrollDownArrow>
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>
</div>
);
}
function CaretUpDownIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & { style?: JSX.CSSProperties },
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="M11 10H5l3 3.5zm0-4H5l3-3.5z" />
</svg>
);
}
function CheckIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & { style?: JSX.CSSProperties },
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="m2.5 8.5 4 4 7-9" />
</svg>
);
}
interface ShippingMethod {
id: string;
name: string;
duration: string;
price: string;
}
const shippingMethods: ShippingMethod[] = [
{
id: 'standard',
name: 'Standard',
duration: 'Delivers in 4-6 business days',
price: '$4.99',
},
{
id: 'express',
name: 'Express',
duration: 'Delivers in 2-3 business days',
price: '$9.99',
},
{
id: 'overnight',
name: 'Overnight',
duration: 'Delivers next business day',
price: '$19.99',
},
];
function CaretUpIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & { style?: JSX.CSSProperties },
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="M12 10H4l4-4.5z" />
</svg>
);
}
function CaretDownIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & { style?: JSX.CSSProperties },
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="M12 6H4l4 4.5z" />
</svg>
);
}
Grouped
Organize related options with <Select.Group> and <Select.GroupLabel> to add section headings inside the popup.
Groups are represented by an array of objects with an items property, which itself is an array of individual items for each group. An extra property, such as value, can be provided for the heading text when rendering the group label.
interface ProduceGroupItem {
value: string;
items: string[];
}
const groups: ProduceGroupItem[] = [
{
value: 'Fruits',
items: ['Apple', 'Banana', 'Orange'],
},
{
value: 'Vegetables',
items: ['Carrot', 'Lettuce', 'Spinach'],
},
];
import { For } from 'solid-js';
import type { JSX } from '@solidjs/web';
import { Select } from 'base-ui-solid/select';
import { Field } from 'base-ui-solid/field';
import styles from './index.module.css';
export default function ExampleSelectGrouped() {
return (
<Field.Root class={styles.Field}>
<Field.Label class={styles.Label} nativeLabel={false} render="div">
Produce
</Field.Label>
<Select.Root items={groupedProduce}>
<Select.Trigger class={styles.Select}>
<Select.Value class={styles.Value} placeholder="Select produce" />
<Select.Icon>
<CaretUpDownIcon />
</Select.Icon>
</Select.Trigger>
<Select.Portal>
<Select.Positioner class={styles.Positioner} sideOffset={4}>
<Select.Popup class={styles.Popup}>
<Select.ScrollUpArrow class={styles.ScrollArrow}>
<CaretUpIcon />
</Select.ScrollUpArrow>
<Select.List class={styles.List}>
<For each={groupedProduce}>
{(group, index) => [
<Select.Group class={styles.Group}>
<Select.GroupLabel class={styles.GroupLabel}>{group.value}</Select.GroupLabel>
<For each={group.items}>
{(item) => (
<Select.Item value={item.value} class={styles.Item}>
<Select.ItemIndicator class={styles.ItemIndicator}>
<CheckIcon />
</Select.ItemIndicator>
<Select.ItemText class={styles.ItemText}>{item.label}</Select.ItemText>
</Select.Item>
)}
</For>
</Select.Group>,
index() < groupedProduce.length - 1 ? (
<Select.Separator class={styles.Separator} />
) : null,
]}
</For>
</Select.List>
<Select.ScrollDownArrow class={styles.ScrollArrow}>
<CaretDownIcon />
</Select.ScrollDownArrow>
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>
</Field.Root>
);
}
function CaretUpDownIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & {
style?: JSX.CSSProperties;
},
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="M11 10H5l3 3.5zm0-4H5l3-3.5z" />
</svg>
);
}
function CheckIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & {
style?: JSX.CSSProperties;
},
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="m2.5 8.5 4 4 7-9" />
</svg>
);
}
const groupedProduce = [
{
value: 'Fruits',
items: [
{ value: 'apple', label: 'Apple' },
{ value: 'banana', label: 'Banana' },
{ value: 'mango', label: 'Mango' },
{ value: 'kiwi', label: 'Kiwi' },
{ value: 'grape', label: 'Grape' },
{ value: 'orange', label: 'Orange' },
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'watermelon', label: 'Watermelon' },
],
},
{
value: 'Vegetables',
items: [
{ value: 'broccoli', label: 'Broccoli' },
{ value: 'carrot', label: 'Carrot' },
{ value: 'cauliflower', label: 'Cauliflower' },
{ value: 'cucumber', label: 'Cucumber' },
{ value: 'kale', label: 'Kale' },
{ value: 'pepper', label: 'Bell pepper' },
{ value: 'spinach', label: 'Spinach' },
{ value: 'zucchini', label: 'Zucchini' },
],
},
];
function CaretUpIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & {
style?: JSX.CSSProperties;
},
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="M12 10H4l4-4.5z" />
</svg>
);
}
function CaretDownIcon(
props: Omit<JSX.IntrinsicElements['svg'], 'style'> & {
style?: JSX.CSSProperties;
},
) {
return (
<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="currentColor"
{...props}
style={{ display: 'block', ...props.style }}
>
<path d="M12 6H4l4 4.5z" />
</svg>
);
}
Custom keyboard shortcuts
<Select.Root> accepts an actionsRef whose highlightItem() action moves the highlight to the 'next', 'previous', 'first' or 'last' item, or clears it with 'none'. Use it to bind shortcuts beyond the built-in arrow keys. Select items receive real DOM focus, so the action moves focus along with the highlight, and 'none' hands focus back to the popup. Select does not loop focus, so 'next' on the last item and 'previous' on the first one leave the highlight where it is. The action does nothing while the popup is closed.
Because the items hold focus while the popup is open, attach the key handler to <Select.Popup> rather than to the trigger:
const actionsRef = { current: null as Select.Root.Actions | null };
<Select.Root actionsRef={actionsRef}>
<Select.Trigger>
<Select.Value />
</Select.Trigger>
<Select.Portal>
<Select.Positioner>
<Select.Popup
onKeyDown={(event) => {
if (event.ctrlKey && event.key === 'j') {
event.preventDefault();
actionsRef.current?.highlightItem('next');
}
}}
>
{/* items */}
</Select.Popup>
</Select.Positioner>
</Select.Portal>
</Select.Root>;
API reference
Root
Groups all parts of the select. Doesn’t render its own HTML element.
namestring—
stringdefaultValueUnion—
value prop instead.Value[] | Value | nullvalueUnion—
Value[] | Value | nullonValueChangefunction—
((value: Value[] | Value | null, eventDetails: Select.Root.ChangeEventDetails) => void)defaultOpenbooleanfalse
open prop instead.booleanopenboolean—
booleanonOpenChangefunction—
((open: boolean, eventDetails: Select.Root.OpenChangeEventDetails) => void)highlightItemOnHoverbooleantrue
:hover to be differentiated from the :focus (data-highlighted) state.booleanactionsRefRefObject<Select.Root.Actions | null>—
unmount: Ends the closing phase of the select after an externally controlled closing animation finishes.
Call preventUnmountOnClose() in onOpenChange first, otherwise the select completes closing on its own.
Whether it leaves the DOM is decided by keepMounted on the portal.close: Closes the select imperatively when called.highlightItem: Moves or clears the highlight while the popup is open.
'next' and 'previous' move sequentially through the items and never wrap: the
highlight stays on the last or first item. 'first' and 'last' highlight the first or
last item. 'none' clears the highlight and hands focus back to the popup.
Calling this action does not open the popup. To highlight an item after opening it, call
the action from onOpenChangeComplete when open is true.RefObject<Select.Root.Actions | null>autoCompletestring—
stringformstring—
stringisItemEqualToValuefunction—
Object.is comparison.((itemValue: Value, value: Value) => boolean)itemToStringLabelfunction—
<Select.Item value={object}>), this function converts the object value to a string representation for display in the trigger.
If the shape of the object is { value, label }, the label will be used automatically without needing to specify this prop.((itemValue: Value) => string)itemToStringValuefunction—
<Select.Item value={object}>), this function converts the object value to a string representation for form submission.
If the shape of the object is { value, label }, the value will be used automatically without needing to specify this prop.((itemValue: Value) => string)itemsUnion—
<Select.Value> renders the label of the selected item instead of the raw value.Record<string, JSX.Element> | ({ label: JSX.Element; value: any })[] | Group[]modalbooleantrue
true: user interaction is limited to the select: document page scroll is locked and pointer interactions on outside elements are disabled.false: user interaction with the rest of the document is allowed. On touch devices, a true modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior.booleanmultiplebooleanfalse
booleanonOpenChangeCompletefunction—
((open: boolean) => void)disabledbooleanfalse
booleanreadOnlybooleanfalse
booleanrequiredbooleanfalse
booleaninputRefRef<HTMLInputElement>—
Ref<HTMLInputElement>idstring—
stringchildrenJSX.Element—
JSX.ElementRoot.State
type SelectRootState = {};Root.Actions
type SelectRootActions = {
unmount: () => void;
close: () => void;
highlightItem: (target: Select.Root.HighlightItemTarget) => void;
};Root.ChangeEventReason
type SelectRootChangeEventReason =
| 'trigger-press'
| 'outside-press'
| 'escape-key'
| 'window-resize'
| 'item-press'
| 'focus-out'
| 'list-navigation'
| 'cancel-open'
| 'imperative-action'
| 'none';Root.ChangeEventDetails
type SelectRootChangeEventDetails = (
| { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
| { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
| { reason: 'escape-key'; event: KeyboardEvent }
| { reason: 'window-resize'; event: UIEvent }
| { reason: 'item-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'focus-out'; event: KeyboardEvent | FocusEvent }
| { reason: 'list-navigation'; event: KeyboardEvent }
| { reason: 'cancel-open'; event: MouseEvent }
| { reason: 'imperative-action'; event: Event }
| { reason: 'none'; event: Event }
) & {
/** Cancels Base UI from handling the event. */
cancel: () => void;
/** Allows the event to propagate in cases where Base UI will stop the propagation. */
allowPropagation: () => void;
/** Indicates whether the event has been canceled. */
isCanceled: boolean;
/** Indicates whether the event is allowed to propagate. */
isPropagationAllowed: boolean;
/** The element that triggered the event, if applicable. */
trigger: Element | undefined;
};Root.HighlightItemTarget
type SelectRootHighlightItemTarget = 'next' | 'previous' | 'first' | 'last' | 'none';Root.OpenChangeEventDetails
type SelectRootOpenChangeEventDetails = (
| { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
| { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
| { reason: 'escape-key'; event: KeyboardEvent }
| { reason: 'window-resize'; event: UIEvent }
| { reason: 'item-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'focus-out'; event: KeyboardEvent | FocusEvent }
| { reason: 'list-navigation'; event: KeyboardEvent }
| { reason: 'cancel-open'; event: MouseEvent }
| { reason: 'imperative-action'; event: Event }
| { reason: 'none'; event: Event }
) & {
/** Cancels Base UI from handling the event. */
cancel: () => void;
/** Allows the event to propagate in cases where Base UI will stop the propagation. */
allowPropagation: () => void;
/** Indicates whether the event has been canceled. */
isCanceled: boolean;
/** Indicates whether the event is allowed to propagate. */
isPropagationAllowed: boolean;
/** The element that triggered the event, if applicable. */
trigger: Element | undefined;
/** Prevents the popup from unmounting until the `unmount` action is called. */
preventUnmountOnClose: () => void;
};Label
An accessible label that is automatically associated with the select trigger.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Label.State
type SelectLabelState = {
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the field has been touched. */
touched: boolean;
/** Whether the field value has changed from its initial value. */
dirty: boolean;
/** Whether the field is valid. */
valid: boolean | null;
/** Whether the field has a value. */
filled: boolean;
/** Whether the field is focused. */
focused: boolean;
};Trigger
A button that opens the select popup.
Renders a <button> element.
nativeButtonbooleantrue
<button> element when replacing it
via the render prop.
Set to false if the rendered element is not a button (for example, <div>).booleandisabledboolean—
booleanchildrenJSX.Element—
JSX.Elementclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-popup-open-—
-data-popup-sideUnion—
'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | nulldata-pressed-—
-data-disabled-—
-data-readonly-—
-data-required-—
-data-valid-—
-data-invalid-—
-data-dirty-—
-data-touched-—
-data-filled-—
-data-focused-—
-data-placeholder-—
-Attribute | Description | |
|---|---|---|
data-popup-open | Present when the corresponding select is open. | |
data-popup-side | Indicates which side the corresponding popup is positioned relative to its anchor. | |
data-pressed | Present when the trigger is pressed. | |
data-disabled | Present when the select is disabled. | |
data-readonly | Present when the select is readonly. | |
data-required | Present when the select is required. | |
data-valid | Present when the select is in a valid state (when wrapped in Field.Root). | |
data-invalid | Present when the select is in an invalid state (when wrapped in Field.Root). | |
data-dirty | Present when the select’s value has changed (when wrapped in Field.Root). | |
data-touched | Present when the select has been touched (when wrapped in Field.Root). | |
data-filled | Present when the select has a value (when wrapped in Field.Root). | |
data-focused | Present when the select trigger is focused (when wrapped in Field.Root). | |
data-placeholder | Present when the select doesn’t have a value. | |
Trigger.State
type SelectTriggerState = {
/** Whether the select popup is currently open. */
open: boolean;
/** Whether the select popup is readonly. */
readOnly: boolean;
/** Indicates which side the corresponding popup is positioned relative to its anchor. */
popupSide: Side | null;
/** The value of the currently selected item. */
value: any;
/** Whether the select doesn't have a value. */
placeholder: boolean;
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the field has been touched. */
touched: boolean;
/** Whether the field value has changed from its initial value. */
dirty: boolean;
/** Whether the field is valid. */
valid: boolean | null;
/** Whether the field has a value. */
filled: boolean;
/** Whether the field is focused. */
focused: boolean;
};Value
A text label of the currently selected item.
Renders a <span> element.
placeholderJSX.Element—
children if specified, or by a null item’s label in items.JSX.Elementchildrenfunction—
JSX.Element to format the selected value.
Treat the value as read-only: in multiple mode it may be a shared frozen array
when nothing is selected.JSX.Element | ((value: any) => JSX.Element)classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-placeholder-—
-Attribute | Description | |
|---|---|---|
data-placeholder | Present when the select doesn’t have a value. | |
Value.State
type SelectValueState = {
/** The value of the currently selected item. */
value: any;
/** Whether the placeholder is being displayed. */
placeholder: boolean;
};Icon
An icon that indicates that the trigger button opens a select popup.
Renders a <span> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-popup-open-—
-Attribute | Description | |
|---|---|---|
data-popup-open | Present when the corresponding popup is open. | |
Icon.State
type SelectIconState = {
/** Whether the select popup is currently open. */
open: boolean;
};Backdrop
An overlay displayed beneath the select popup.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-open-—
-data-closed-—
-data-starting-style-—
-data-ending-style-—
-Attribute | Description | |
|---|---|---|
data-open | Present when the select is open. | |
data-closed | Present when the select is closed. | |
data-starting-style | Present when the select begins animating in. | |
data-ending-style | Present when the select is animating out. | |
Backdrop.State
type SelectBackdropState = {
/** Whether the component is open. */
open: boolean;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
};Portal
A portal element that moves the popup to a different part of the DOM.
By default, the portal element is appended to <body>.
Renders a <div> element.
containerUnion—
HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null> | nullclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Portal.State
type SelectPortalState = {};Positioner
Positions the select popup.
Renders a <div> element.
alignItemWithTriggerbooleantrue
booleandisableAnchorTrackingbooleanfalse
booleanalignAlign'center'
AlignalignOffsetUnion0
data object parameter with the following properties: data.anchor: the dimensions of the anchor element with properties width and height.data.positioner: the dimensions of the positioner element with properties width and height.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.number | OffsetFunctionsideSide'bottom'
SidesideOffsetUnion0
data object parameter with the following properties: data.anchor: the dimensions of the anchor element with properties width and height.data.positioner: the dimensions of the positioner element with properties width and height.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.number | OffsetFunctionarrowPaddingnumber5
numberanchorfunction—
Element | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null) | nullcollisionAvoidanceCollisionAvoidance—
side controls overflow on the preferred placement axis (top/bottom or left/right): 'flip': keep the requested side when it fits; otherwise try the opposite side
(top and bottom, or left and right).'shift': never change side; keep the requested side and move the popup within
the clipping boundary so it stays visible.'none': do not correct side-axis overflow. align controls overflow on the alignment axis (start/center/end): 'flip': keep side, but swap start and end when the requested alignment overflows.'shift': keep side and requested alignment, then nudge the popup along the
alignment axis to fit.'none': do not correct alignment-axis overflow. fallbackAxisSide controls fallback behavior on the perpendicular axis when the
preferred axis cannot fit: 'start': allow perpendicular fallback and try the logical start side first
(top before bottom, or left before right in LTR).'end': allow perpendicular fallback and try the logical end side first
(bottom before top, or right before left in LTR).'none': do not fallback to the perpendicular axis. When side is 'shift', explicitly setting align only supports 'shift' or 'none'.
If align is omitted, it defaults to 'flip'.CollisionAvoidancecollisionBoundaryBoundary'clipping-ancestors'
BoundarycollisionPaddingPadding5
Paddingstickybooleanfalse
booleanpositionMethodUnion'absolute'
position property to use.'absolute' | 'fixed'classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-open-—
-data-closed-—
-data-anchor-hidden-—
-data-alignUnion—
'start' | 'center' | 'end'data-sideUnion—
'none' | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'Attribute | Description | |
|---|---|---|
data-open | Present when the select popup is open. | |
data-closed | Present when the select popup is closed. | |
data-anchor-hidden | Present when the anchor is hidden. | |
data-align | Indicates how the popup is aligned relative to specified side. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
CSS variables
--anchor-heightnumber—
number--anchor-widthnumber—
number--available-heightnumber—
number--available-widthnumber—
number--transform-originstring—
stringCSS Variable | Description | |
|---|---|---|
--anchor-height | The anchor’s height. | |
--anchor-width | The anchor’s width. | |
--available-height | The available height between the trigger and the edge of the viewport. | |
--available-width | The available width between the trigger and the edge of the viewport. | |
--transform-origin | The coordinates that this element is anchored to. Used for animations and transitions. | |
Positioner.State
type SelectPositionerState = {
/** Whether the component is open. */
open: boolean;
/** The side of the anchor the component is placed on. */
side: Side | 'none';
/** The alignment of the component relative to the anchor. */
align: Align;
/** Whether the anchor element is hidden. */
anchorHidden: boolean;
};Popup
A container for the select list.
Renders a <div> element.
finalFocusfunction—
false: Do not move focus.true: Move focus based on the default behavior (trigger or previously focused element).RefObject: Move focus to the ref element.function: Called with the interaction type (mouse, touch, pen, or keyboard).
Return an element to focus, true to use the default behavior, or false/undefined to do nothing.boolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null)childrenJSX.Element—
JSX.Elementclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-open-—
-data-closed-—
-data-alignUnion—
'start' | 'center' | 'end'data-sideUnion—
'none' | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'data-starting-style-—
-data-ending-style-—
-Attribute | Description | |
|---|---|---|
data-open | Present when the select is open. | |
data-closed | Present when the select is closed. | |
data-align | Indicates how the popup is aligned relative to specified side. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
data-starting-style | Present when the select begins animating in. | |
data-ending-style | Present when the select is animating out. | |
Popup.State
type SelectPopupState = {
/** The side of the anchor the component is placed on. */
side: Side | 'none';
/** The alignment of the component relative to the anchor. */
align: Align;
/** Whether the component is open. */
open: boolean;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
};List
A container for the select items.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)List.State
type SelectListState = {};Arrow
Displays an element positioned against the select popup anchor.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-open-—
-data-closed-—
-data-uncentered-—
-data-alignUnion—
'start' | 'center' | 'end'data-sideUnion—
'none' | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'Attribute | Description | |
|---|---|---|
data-open | Present when the select popup is open. | |
data-closed | Present when the select popup is closed. | |
data-uncentered | Present when the select arrow is uncentered. | |
data-align | Indicates how the popup is aligned relative to specified side. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
Arrow.State
type SelectArrowState = {
/** Whether the select popup is currently open. */
open: boolean;
/** The side of the anchor the component is placed on. */
side: Side | 'none';
/** The alignment of the component relative to the anchor. */
align: Align;
/** Whether the arrow cannot be centered on the anchor. */
uncentered: boolean;
};Item
An individual option in the select popup.
Renders a <div> element.
labelstring—
stringvalueanynull
anynativeButtonbooleanfalse
<button> element when replacing it
via the render prop.
Set to true if the rendered element is a native button.booleandisabledbooleanfalse
booleanchildrenJSX.Element—
JSX.Elementclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-selected-—
-data-highlighted-—
-data-disabled-—
-Attribute | Description | |
|---|---|---|
data-selected | Present when the select item is selected. | |
data-highlighted | Present when the select item is highlighted. | |
data-disabled | Present when the select item is disabled. | |
Item.State
type SelectItemState = {
/** Whether the item should ignore user interaction. */
disabled: boolean;
/** Whether the item is selected. */
selected: boolean;
/** Whether the item is highlighted. */
highlighted: boolean;
};ItemText
A text label of the select item.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)ItemText.State
type SelectItemTextState = {};ItemIndicator
Indicates whether the select item is selected.
Renders a <span> element.
childrenJSX.Element—
JSX.Elementclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)keepMountedboolean—
booleanrenderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-starting-style-—
-data-ending-style-—
-Attribute | Description | |
|---|---|---|
data-starting-style | Present when the indicator begins animating in. | |
data-ending-style | Present when the indicator is animating out. | |
ItemIndicator.State
type SelectItemIndicatorState = {
/** Whether the item is selected. */
selected: boolean;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
};Group
Groups related select items with the corresponding label.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Group.State
type SelectGroupState = {};GroupLabel
An accessible label that is automatically associated with its parent group.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)GroupLabel.State
type SelectGroupLabelState = {};ScrollUpArrow
An element that scrolls the select popup up when hovered. Does not render when using touch input.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)keepMountedbooleanfalse
booleanrenderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-direction'up'—
'up'data-sideUnion—
'none' | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'data-visible-—
-data-starting-style-—
-data-ending-style-—
-Attribute | Description | |
|---|---|---|
data-direction | Indicates the direction of the scroll arrow. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
data-visible | Present when the scroll arrow is visible. | |
data-starting-style | Present when the scroll arrow begins animating in. | |
data-ending-style | Present when the scroll arrow is animating out. | |
ScrollUpArrow.State
type SelectScrollUpArrowState = {};ScrollDownArrow
An element that scrolls the select popup down when hovered. Does not render when using touch input.
Renders a <div> element.
classfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)keepMountedbooleanfalse
booleanrenderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-direction'down'—
'down'data-sideUnion—
'none' | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'data-visible-—
-data-starting-style-—
-data-ending-style-—
-Attribute | Description | |
|---|---|---|
data-direction | Indicates the direction of the scroll arrow. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
data-visible | Present when the scroll arrow is visible. | |
data-starting-style | Present when the scroll arrow begins animating in. | |
data-ending-style | Present when the scroll arrow is animating out. | |
ScrollDownArrow.State
type SelectScrollDownArrowState = {};Separator
A visual separator between items or groups.
Renders a <div> element.
orientationOrientation'horizontal'
Orientationclassfunction—
JSX.ClassValue | ((state) => JSX.ClassValue)stylefunction—
JSX.CSSProperties | string | ((state) => JSX.CSSProperties | string | undefined)renderfunction—
keyof JSX.IntrinsicElements | Component | ((props, state) => JSX.Element)Data attributes
data-orientationUnion—
'horizontal' | 'vertical'Attribute | Description | |
|---|---|---|
data-orientation | Indicates the orientation of the separator. | |
Separator.State
type SelectSeparatorState = {
/** The orientation of the separator. */
orientation: Orientation;
};