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-svelte/select

Usage

<script lang="ts">
  import * as Select from "$lib/components/ui/select/index.js";
</script>
<Select.Root type="single">
  <Select.Trigger class="w-[180px]"></Select.Trigger>
  <Select.Content>
    <Select.Item value="light">Light</Select.Item>
    <Select.Item value="dark">Dark</Select.Item>
    <Select.Item value="system">System</Select.Item>
  </Select.Content>
</Select.Root>

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.Field data-invalid>
  <Field.Label>Fruit</Field.Label>
  <Select.Trigger aria-invalid="true">
    Select a fruit
  </Select.Trigger>
</Field.Field>

RTL

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

API Reference

See the Radix UI Select documentation.