Select
Displays a list of options for the user to pick from, triggered by a button.
Preview
Installation
npx sigma-ui@latest add selectUsage
<script setup lang="ts">
import {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
</script>
<template>
<Select>
<SelectTrigger>
<SelectValue placeholder="Select a fruit" />
</SelectTrigger>
<SelectContent>
<SelectGroup>
<SelectLabel>Fruits</SelectLabel>
<SelectItem value="apple">
Apple
</SelectItem>
</SelectGroup>
</SelectContent>
</Select>
</template>- Use
v-modelto control the selected value, ordefaultValueto set an initial one. SelectValueshows the selected item, or itsplaceholderwhen nothing is selected.sizeonSelectTriggerisdefaultorsm. The selected item shows a check on the right.
Examples
Scrollable
Form
API Reference
Select
Props
| Prop | Type | Default |
|---|---|---|
openThe controlled open state of the Select. Can be bind as | boolean | - |
defaultOpenThe open state of the select when it is initially rendered. Use when you do not need to control its open state. | boolean | - |
defaultValueThe value of the select when initially rendered. Use when you do not need to control the state of the Select | AcceptableValue | AcceptableValue[] | - |
modelValueThe controlled value of the Select. Can be bind as | AcceptableValue | AcceptableValue[] | - |
nullableValueThe value of the hidden native select option when the model value is nullish. | string | - |
byUse this to compare objects by a particular field, or pass your own comparison function for complete control over how objects are compared. | string | ((a: AcceptableValue, b: AcceptableValue) => boolean) | - |
dirThe reading direction of the combobox when applicable. <br> If omitted, inherits globally from | Direction | - |
multipleWhether multiple options can be selected or not. | boolean | - |
autocompleteNative html input | string | - |
disabledWhen | boolean | - |
nameThe name of the field. Submitted with its owning form as part of a name/value pair. | string | - |
requiredWhen | boolean | - |
Events
| Event | Payload |
|---|---|
update:modelValueEvent handler called when the value changes. | [value: AcceptableValue] |
update:openEvent handler called when the open state of the context menu changes. | [value: boolean] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
SelectValue
Props
| Prop | Type | Default |
|---|---|---|
placeholderThe content that will be rendered inside the | string | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
SelectTrigger
Props
| Prop | Type | Default |
|---|---|---|
sizeHeight of the trigger. | "default" | "sm" | "default" |
disabled | boolean | - |
referenceThe reference (or anchor) element that is being referred to for positioning. If not provided will use the current component as anchor. | ReferenceElement | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
SelectContent
Props
| Prop | Type | Default |
|---|---|---|
forceMountUsed to force mounting when more control is needed. Useful when controlling animation with Vue animation libraries. | boolean | - |
positionThe positioning mode to use
| "popper" | "item-aligned" | "popper" |
bodyLockThe document.body will be lock, and scrolling will be disabled. | boolean | true |
loopWhen | boolean | false |
memoDependenciesReactive dependencies that should invalidate the memoized content subtree. | unknown[] | - |
sideThe preferred side of the trigger to render against when open. Will be reversed when collisions occur and avoidCollisions is enabled. | "top" | "right" | "bottom" | "left" | "bottom" |
sideOffsetThe distance in pixels from the trigger. | number | 0 |
sideFlipFlip to the opposite side when colliding with boundary. | boolean | true |
alignThe preferred alignment against the trigger. May change when collisions occur. | "center" | "start" | "end" | "center" |
alignOffsetAn offset in pixels from the | number | 0 |
alignFlipFlip alignment when colliding with boundary.
May only occur when | boolean | true |
avoidCollisionsWhen | boolean | true |
collisionBoundaryThe element used as the collision boundary. By default this is the viewport, though you can provide additional element(s) to be included in this check. | Element | (Element | null)[] | null | [] |
collisionPaddingThe distance in pixels from the boundary edges where collision detection should occur. Accepts a number (same for all sides), or a partial padding object, for example: { top: 20, left: 20 }. | number | Partial<Record<"top" | "right" | "bottom" | "left", number>> | 0 |
arrowPaddingThe padding between the arrow and the edges of the content. If your content has border-radius, this will prevent it from overflowing the corners. | number | 0 |
hideShiftedArrowWhen | boolean | true |
stickyThe sticky behavior on the align axis. | "partial" | "always" | "partial" |
hideWhenDetachedWhether to hide the content when the trigger becomes fully occluded. | boolean | false |
positionStrategyThe type of CSS position property to use. | "absolute" | "fixed" | - |
updatePositionStrategyStrategy to update the position of the floating element on every animation frame. | "always" | "optimized" | 'optimized' |
disableUpdateOnLayoutShiftWhether to disable the update position for the content when the layout shifted. | boolean | false |
prioritizePositionForce content to be position within the viewport. Might overlap the reference element, which may not be desired. | boolean | false |
referenceThe custom element or virtual element that will be set as the reference to position the floating element. If provided, it will replace the default anchor element. | ReferenceElement | - |
dirThe reading direction of the popper content when applicable. <br> If omitted, inherits globally from | Direction | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
disableOutsidePointerEventsWhen | boolean | - |
Events
| Event | Payload |
|---|---|
escapeKeyDownEvent handler called when the escape key is down. Can be prevented. | [event: KeyboardEvent] |
pointerDownOutsideEvent handler called when a | [event: PointerDownOutsideEvent] |
closeAutoFocus | [event: Event] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
SelectGroup
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
SelectItem
Props
| Prop | Type | Default |
|---|---|---|
valuerequiredThe value given as data when submitted with a | AcceptableValue | - |
disabledWhen | boolean | - |
textValueOptional text used for typeahead purposes. By default the typeahead behavior will use the Use this when the content is complex, or you have non-textual content inside. | string | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
SelectItemText
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
SelectLabel
Props
| Prop | Type | Default |
|---|---|---|
for | string | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
SelectSeparator
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
SelectScrollUpButton
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
SelectScrollDownButton
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
Accessibility
Adheres to the ListBox WAI-ARIA design pattern. Reka UI handles the roles, focus management, and typeahead.
| Key | Description |
|---|---|
| Space | When focus is on the trigger, opens the select and focuses the selected item. When focus is on an item, selects it. |
| Enter | When focus is on the trigger, opens the select and focuses the selected item. When focus is on an item, selects it. |
| ArrowDown | When focus is on the trigger, opens the select. When focus is on an item, moves focus to the next item. |
| ArrowUp | When focus is on the trigger, opens the select. When focus is on an item, moves focus to the previous item. |
| Esc | Closes the select and moves focus to the trigger. |