120k

Select

Displays a list of options for the user to pick from—triggered by a button.

Installation

pnpm dlx shadcn@latest add @force-ui-vue/select

Usage

<script setup lang="ts">
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select"
</script>
 
<template>
  <Select>
    <SelectTrigger>
      <SelectValue placeholder="Select a fruit" />
    </SelectTrigger>
    <SelectContent>
      <SelectItem value="apple"> Apple </SelectItem>
      <SelectItem value="banana"> Banana </SelectItem>
      <SelectItem value="blueberry"> Blueberry </SelectItem>
      <SelectItem value="grapes"> Grapes </SelectItem>
      <SelectItem value="pineapple"> Pineapple </SelectItem>
    </SelectContent>
  </Select>
</template>

Composition

Use the following composition to build a Select:

Select
├── SelectTrigger
│   └── SelectValue
└── SelectContent
    ├── SelectGroup
    │   ├── SelectLabel
    │   ├── SelectItem
    │   └── SelectItem
    ├── SelectSeparator
    └── SelectGroup
        ├── SelectLabel
        ├── SelectItem
        └── SelectItem

Examples

Align Item With Trigger

Use the position prop on SelectContent to control alignment. When position="item-aligned" (default), the popup positions so the selected item appears over the trigger. When position="popper", the popup aligns to the trigger edge.

Groups

Use SelectGroup, SelectLabel, and SelectSeparator to organize items.

Scrollable

A select with many items that scrolls.

Disabled

Invalid

Add the data-invalid attribute to the Field component and the aria-invalid attribute to the SelectTrigger component to show an error state.

<Field data-invalid>
  <FieldLabel>Fruit</FieldLabel>
  <SelectTrigger aria-invalid="true">
    <SelectValue />
  </SelectTrigger>
</Field>

RTL

To enable RTL support in Force UI, see the RTL configuration guide.

API Reference

See the Radix UI Select documentation.