Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Select for Astro

Astro selection popups with labelled options and data-slot behavior.

API Reference

Installation

bunx --bun shadcn@latest add @gnostic/select

Usage

---
import {
  Select,
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@/components/ui/select"
---
<Select class="w-[180px]" placeholder="Select a fruit">
  <SelectTrigger>
    <SelectValue />
  </SelectTrigger>
  <SelectContent>
    <SelectGroup>
      <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>
    </SelectGroup>
  </SelectContent>
</Select>

Composition

Arrange the parts as shown for a Select:

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

Examples

Item Aligned

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.

Item aligned

Popper

With Groups & Labels

Group related choices with SelectGroup, give the group a SelectLabel, and place SelectSeparator between groups when needed.

Large List

A select with many items that scrolls.

Disabled

Disable the entire select or individual items.

Disabled item

Disabled select

API Reference

SelectProps

PropType
defaultValue?string

Initial selected value

Typestring
defaultOpen?boolean

Initial open state

Typeboolean
placeholder?string

Placeholder text when no value selected

Typestring
mountStrategy?MountStrategy

Detach closed content by default; eager keeps it connected and hidden.

TypeMountStrategy
disabled?boolean

Disable interaction

Typeboolean
required?boolean

Form validation required

Typeboolean
name?string

Form field name (auto-creates an internal form control)

Typestring
position?Position

Positioning mode for the content. - "item-aligned": Positions content so selected item aligns with trigger (like native select) - "popper": Positions content below/above trigger like a dropdown

TypePosition
Default"item-aligned"
side?Side

The preferred side of the trigger to render against. Will be reversed when collisions occur and `avoidCollisions` is enabled.

TypeSide
Default"bottom"
align?Align

The preferred alignment against the trigger. May change when collisions occur.

TypeAlign
Default"start"
sideOffset?number

The distance in pixels from the trigger.

Typenumber
Default4
alignOffset?number

An offset in pixels from the "start" or "end" alignment options.

Typenumber
Default0
avoidCollisions?boolean

When true, overrides side/align preferences to prevent collisions with viewport edges.

Typeboolean
Defaulttrue
collisionPadding?number

The padding between the content and the viewport edges when avoiding collisions.

Typenumber
Default8
highlightItemOnHover?boolean

Whether moving the pointer over items should highlight and focus them.

Typeboolean
Defaulttrue
lockScroll?boolean

Lock body scroll when open.

Typeboolean
Defaulttrue

SelectContentProps

PropType
position?Position

Positioning mode for the content. - "item-aligned": Positions content so selected item aligns with trigger (like native select) - "popper": Positions content below/above trigger like a dropdown

TypePosition
Default"item-aligned"
side?Side

The preferred side of the trigger to render against. Will be reversed when collisions occur and `avoidCollisions` is enabled.

TypeSide
Default"bottom"
align?Align

The preferred alignment against the trigger. May change when collisions occur.

TypeAlign
Default"start"
sideOffset?number

The distance in pixels from the trigger.

Typenumber
Default4
alignOffset?number

An offset in pixels from the "start" or "end" alignment options.

Typenumber
Default0
avoidCollisions?boolean

When true, overrides side/align preferences to prevent collisions with viewport edges.

Typeboolean
Defaulttrue
collisionPadding?number

The padding between the content and the viewport edges when avoiding collisions.

Typenumber
Default8

See the data-slot docs for more information on interactivity.

Events

Dispatch these events on the select root. The root emits the outbound events.

Outbound events

Event Detail
select:change { value: string | null }
select:open-change { open: boolean }

Inbound events

Event Detail
select:set { value?: string | null, open?: boolean }

Read the installed source for the complete prop types.

When to use Select

Use Select for one choice from a known set. Compose trigger, value, content, and items under one root. Give items stable values and provide a visible label for the field.

Keyboard and behavior

The data-slot controller handles the popup and keyboard selection. Check arrow keys, Enter, Escape, and the submitted value. The existing SelectLabel part styles a group label inside the list; it does not replace the field’s external label.

Theme and layout

The trigger and popup share input and popover tokens. Test long option labels and disabled states. This Astro API retains its current size options and DOM events instead of adopting React callbacks.