Select

A dropdown for choosing one option from a short list. The value type is generic.

Status: stable. Category: Forms.

import { Select, SelectItem } from '@glyphui/ui'

Exports: Select, SelectItem, selectStyles.

Notes

  • For long lists or search, use Combobox.

Select props

PropTypeDefaultDescription
aria-describedbystring
aria-invalidboolean
aria-labelstring
classNamestring
contentClassNamestring
defaultValuestring
idstring
onValueChange((value: T) => void)
placeholderReactNode
size"sm" | "md" | "lg"
valuestring

Example: In a field

import { Field, Select, SelectItem } from '@glyphui/ui'

export default function Example() {
  return (
    <Field label="Region" className="max-w-xs">
      <Select placeholder="Choose a region" defaultValue="eu">
        <SelectItem value="us">United States</SelectItem>
        <SelectItem value="eu">Europe (Frankfurt)</SelectItem>
        <SelectItem value="ap">Asia Pacific (Tokyo)</SelectItem>
      </Select>
    </Field>
  )
}

Example: Typed values

Select<Plan> only accepts and emits Plan values.

import { Select, SelectItem, Text } from '@glyphui/ui'
import { useState } from 'react'

type Plan = 'free' | 'pro' | 'team'

export default function Example() {
  const [plan, setPlan] = useState<Plan>('pro')
  return (
    <div className="grid max-w-xs gap-2">
      <Select<Plan> value={plan} onValueChange={setPlan} aria-label="Plan">
        <SelectItem value="free">Free</SelectItem>
        <SelectItem value="pro">Pro</SelectItem>
        <SelectItem value="team">Team</SelectItem>
      </Select>
      <Text size="small" tone="muted">
        Selected: <span className="font-mono">{plan}</span>
      </Text>
    </div>
  )
}

Live page: https://glyphui.xyz/components/select