Prototyper UI

Select

A dropdown select input built on Base UI

Loading...

Installation

pnpm dlx shadcn@latest add https://prototyper-ui.com/r/select.json
npx shadcn@latest add https://prototyper-ui.com/r/select.json
yarn dlx shadcn@latest add https://prototyper-ui.com/r/select.json
bunx --bun shadcn@latest add https://prototyper-ui.com/r/select.json

This will add the following files to your project:

  • components/ui/select.tsx

Usage

import {
  Select,
  SelectTrigger,
  SelectValue,
  SelectContent,
  SelectItem,
} from "@/components/ui/select"

<Select>
  <SelectTrigger>
    <SelectValue placeholder="Select an option" />
  </SelectTrigger>
  <SelectContent>
    <SelectItem value="option-1">Option 1</SelectItem>
    <SelectItem value="option-2">Option 2</SelectItem>
  </SelectContent>
</Select>

Anatomy

<Select>
  <SelectTrigger>
    <SelectValue />
  </SelectTrigger>
  <SelectContent>
    <SelectGroup>
      <SelectLabel />
      <SelectItem />
    </SelectGroup>
    <SelectSeparator />
  </SelectContent>
</Select>
Sub-componentdata-slotPurposeRequired
SelectselectRoot provider, manages selection stateYes
SelectTriggerselect-triggerButton that opens the dropdownYes
SelectValueselect-valueDisplays the currently selected valueYes
SelectContentselect-contentPopup container for itemsYes
SelectItemselect-itemAn individual selectable optionYes
SelectGroupselect-groupGroups related items togetherNo
SelectLabelselect-labelLabel for a group of itemsNo
SelectSeparatorselect-separatorVisual divider between items or groupsNo
SelectScrollUpButtonselect-scroll-up-buttonScroll indicator at the top of the listNo
SelectScrollDownButtonselect-scroll-down-buttonScroll indicator at the bottom of the listNo

Examples

Content

Loading...

Description

Loading...

Disabled

Loading...

Disabled Items

Loading...
Loading...

Reusable

Loading...

Sections

Loading...

Sections Dynamic

Loading...

Text Slots

Loading...

Validation

Loading...

Styling

Data Slots

Use data-slot attributes to target specific parts of the select:

Slot nameElement
selectRoot provider
select-triggerThe trigger button
select-valueDisplayed selected value text
select-contentThe dropdown popup panel
select-itemAn individual option
select-groupGroup wrapper for related items
select-labelLabel for a group
select-separatorVisual divider
select-scroll-up-buttonTop scroll indicator
select-scroll-down-buttonBottom scroll indicator

Customization Examples

/* Make the trigger wider */
[data-slot="select-trigger"] {
  @apply w-64;
}

/* Custom highlight color for items */
[data-slot="select-item"][data-highlighted] {
  @apply bg-primary text-primary-foreground;
}
{/* Override trigger size via className */}
<SelectTrigger className="w-80">
  <SelectValue placeholder="Choose..." />
</SelectTrigger>

API Reference

Select

Root component that manages selection state and context.

Prop

Type

All Base UI Select.Root props are forwarded via ...props.

SelectTrigger

Button that opens the dropdown when clicked.

Prop

Type

All Base UI Select.Trigger props are forwarded via ...props.

SelectValue

Displays the currently selected value or a placeholder.

Prop

Type

All Base UI Select.Value props are forwarded via ...props.

SelectContent

The dropdown popup panel rendered inside a portal with positioning.

Prop

Type

All Base UI Select.Popup props are forwarded via ...props.

SelectItem

An individual selectable option within the dropdown.

Prop

Type

All Base UI Select.Item props are forwarded via ...props.

SelectGroup

Groups related items together with optional label.

Prop

Type

All Base UI Select.Group props are forwarded via ...props.

SelectLabel

Label for a group of items.

Prop

Type

All Base UI Select.GroupLabel props are forwarded via ...props.

SelectSeparator

Visual divider between items or groups.

Prop

Type

All Base UI Select.Separator props are forwarded via ...props.

SelectScrollUpButton

Scroll indicator at the top of the dropdown list.

Prop

Type

All Base UI Select.ScrollUpArrow props are forwarded via ...props.

SelectScrollDownButton

Scroll indicator at the bottom of the dropdown list.

Prop

Type

All Base UI Select.ScrollDownArrow props are forwarded via ...props.

selectTriggerVariants

A cva helper exported for use outside of the <SelectTrigger> component (e.g., applying select trigger styles to custom elements).

import { selectTriggerVariants } from "@/components/ui/select"

<div className={selectTriggerVariants({ size: "sm" })}>Custom trigger</div>

Accessibility

Keyboard Interactions

KeyAction
SpaceOpens the dropdown or selects the highlighted item
EnterOpens the dropdown or selects the highlighted item
ArrowDownOpens the dropdown or moves highlight to the next item
ArrowUpOpens the dropdown or moves highlight to the previous item
HomeMoves highlight to the first item
EndMoves highlight to the last item
EscapeCloses the dropdown
TabCloses the dropdown and moves focus to the next element

ARIA Attributes

  • The trigger renders with role="combobox" and aria-haspopup="listbox".
  • aria-expanded is set to true when the dropdown is open.
  • The popup receives role="listbox".
  • Each item receives role="option" with aria-selected indicating the current selection.
  • aria-disabled is set on disabled items.
  • Screen readers announce the currently selected value from the trigger.

Stream UI

This component is available in @prototyperai/stream-ui.

Catalog Definition

select.catalog.ts
import { z } from "zod"
import { defineComponent } from "@prototyperai/stream-ui/catalog"

export default defineComponent({
  description: "A dropdown select field for choosing from a list of options",
  props: z.object({
    label: z.string().optional().describe("Label displayed above the select"),
    placeholder: z.string().optional().describe("Placeholder text when no value is selected"),
    options: z
      .array(
        z.object({
          label: z.string().describe("Display text for the option"),
          value: z.string().describe("Value of the option"),
        }),
      )
      .describe("List of selectable options"),
    value: z.string().optional().describe("Currently selected value"),
    disabled: z.boolean().optional().describe("Whether the select is disabled"),
  }),
  events: ["change"],
  example: {
    label: "Country",
    placeholder: "Select a country...",
    options: [
      { label: "United States", value: "us" },
      { label: "Canada", value: "ca" },
      { label: "United Kingdom", value: "uk" },
    ],
  },
})

Example Spec

{
  "root": "countrySelect",
  "elements": {
    "countrySelect": {
      "type": "Select",
      "props": {
        "label": "Country",
        "placeholder": "Select a country...",
        "options": [
          { "label": "United States", "value": "us" },
          { "label": "Canada", "value": "ca" },
          { "label": "United Kingdom", "value": "uk" }
        ]
      },
      "$bindState": { "path": "/country", "event": "change" }
    }
  }
}

Learn more in the Stream UI documentation.

On this page