Skip to Content

Select

A dropdown for choosing one option from a list.

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

export function Demo() {
  return (
    <Select defaultValue="usd">
      <SelectTrigger className="w-48" aria-label="Currency">
        <SelectValue placeholder="Currency" />
      </SelectTrigger>
      <SelectContent>
        <SelectItem value="usd">USD</SelectItem>
        <SelectItem value="eur">EUR</SelectItem>
        <SelectItem value="gbp">GBP</SelectItem>
      </SelectContent>
    </Select>
  )
}

Installation

npm i @dapplelight/signet-ui

Usage

import {
  Select,
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectLabel,
  SelectSeparator,
  SelectTrigger,
  SelectValue,
} from "@dapplelight/signet-ui/components/select"

<Select>
  <SelectTrigger className="w-48">
    <SelectValue placeholder="Currency" />
  </SelectTrigger>
  <SelectContent>
    <SelectItem value="usd">USD</SelectItem>
  </SelectContent>
</Select>

Built on Base UI's Select.

Examples

Groups

import {
  Select,
  SelectContent,
  SelectGroup,
  SelectItem,
  SelectLabel,
  SelectSeparator,
  SelectTrigger,
  SelectValue,
} from "@dapplelight/signet-ui/components/select"

<Select>
  <SelectTrigger className="w-56" aria-label="Region">
    <SelectValue placeholder="Choose a region" />
  </SelectTrigger>
  <SelectContent>
    <SelectGroup>
      <SelectLabel>Americas</SelectLabel>
      <SelectItem value="us-east">US East</SelectItem>
      <SelectItem value="us-west">US West</SelectItem>
    </SelectGroup>
    <SelectSeparator />
    <SelectGroup>
      <SelectLabel>Europe</SelectLabel>
      <SelectItem value="eu-west">EU West</SelectItem>
      <SelectItem value="eu-central">EU Central</SelectItem>
    </SelectGroup>
  </SelectContent>
</Select>

Controlled

Status: pending

import { useState } from "react"
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from "@dapplelight/signet-ui/components/select"

const [status, setStatus] = useState<string | null>("pending")

<Select value={status} onValueChange={setStatus}>
  <SelectTrigger className="w-48" aria-label="Order status">
    <SelectValue placeholder="Status" />
  </SelectTrigger>
  <SelectContent>
    <SelectItem value="pending">Pending</SelectItem>
    <SelectItem value="shipped">Shipped</SelectItem>
    <SelectItem value="delivered">Delivered</SelectItem>
  </SelectContent>
</Select>

Small

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

<Select defaultValue="30">
  <SelectTrigger size="sm" className="w-36" aria-label="Range">
    <SelectValue />
  </SelectTrigger>
  <SelectContent>
    <SelectItem value="7">Last 7 days</SelectItem>
    <SelectItem value="30">Last 30 days</SelectItem>
  </SelectContent>
</Select>

Disabled and invalid

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

<Select disabled defaultValue="usd">
  <SelectTrigger className="w-40" aria-label="Currency">
    <SelectValue />
  </SelectTrigger>
  <SelectContent>
    <SelectItem value="usd">USD</SelectItem>
  </SelectContent>
</Select>

<Select>
  <SelectTrigger className="w-40" aria-label="Plan" aria-invalid>
    <SelectValue placeholder="Plan (required)" />
  </SelectTrigger>
  <SelectContent>
    <SelectItem value="team">Team</SelectItem>
  </SelectContent>
</Select>

API Reference

Select

Base UI's Select root. Common props:

PropTypeDefaultDescription
valueValue | null-Controlled value.
defaultValueValue | null-Initial value when uncontrolled.
onValueChange(value: Value | null, details) => void-Called when the selection changes.
multiplebooleanfalseAllow several values; value becomes an array.
itemsRecord<string, ReactNode> | { label, value }[]-Lets SelectValue show an item's label instead of its raw value.
openboolean-Controlled open state.
defaultOpenbooleanfalseInitial open state.
onOpenChange(open: boolean, details) => void-Called when the popup opens or closes.
modalbooleantrueBlock outside interaction while open.
namestring-Form field name.
disabledbooleanfalseDisable the select.
readOnlybooleanfalseShow the value but block changes.
requiredbooleanfalseRequire a choice in a form.

SelectTrigger

PropTypeDefaultDescription
size"sm" | "default""default"Trigger height.
classNamestring-Class on the trigger. aria-invalid shows the error style.

SelectValue

PropTypeDefaultDescription
placeholderReactNode-Shown while nothing is selected.
childrenReactNode | ((value) => ReactNode)-Custom text for the selected value.

SelectContent

PropTypeDefaultDescription
side"top" | "bottom" | "left" | "right" | "inline-start" | "inline-end""bottom"Preferred side.
sideOffsetnumber4Gap from the trigger.
align"start" | "center" | "end""center"Alignment against the trigger.
alignOffsetnumber0Offset along the alignment axis.
alignItemWithTriggerbooleantrueLine the selected item up over the trigger.

SelectItem

PropTypeDefaultDescription
valueValue-This option's value; any type, matching the root.
disabledbooleanfalseDisable this option.
childrenReactNode-Label. A truncated label shows a tooltip on hover.

SelectGroup / SelectLabel / SelectSeparator

PropTypeDefaultDescription
classNamestring-Group options under a label, and split groups with a separator.