SegmentedControl

Pick exactly one of a few options. The value type is inferred from the options.

Status: stable. Category: Forms.

import { SegmentedControl } from '@glyphui/ui'

Exports: SegmentedControl, segmentedControlStyles.

Notes

  • Never deselects: clicking the active option keeps it selected.

SegmentedControl props

PropTypeDefaultDescription
options (required)readonly SegmentedOption<T>[]
aria-labelstringRequired unless the control sits in a <Field label>, which labels it.
aria-labelledbystring
classNamestring
defaultValuestring
fullWidthboolean
idstring
onValueChange((value: T) => void)
size"sm" | "md"
valuestring

Example: Basic

import { SegmentedControl } from '@glyphui/ui'
import { useState } from 'react'

export default function Example() {
  const [view, setView] = useState<'list' | 'board' | 'timeline'>('board')
  return (
    <SegmentedControl
      aria-label="View"
      value={view}
      onValueChange={setView}
      options={[
        { value: 'list', label: 'List' },
        { value: 'board', label: 'Board' },
        { value: 'timeline', label: 'Timeline' },
      ]}
    />
  )
}

Example: Full width

import { SegmentedControl } from '@glyphui/ui'

export default function Example() {
  return (
    <div className="max-w-sm">
      <SegmentedControl
        aria-label="Billing period"
        fullWidth
        defaultValue="yearly"
        options={[
          { value: 'monthly', label: 'Monthly' },
          { value: 'yearly', label: 'Yearly · save 20%' },
        ]}
      />
    </div>
  )
}

Live page: https://glyphui.xyz/components/segmented-control