Components

Segmented Control

Picks one of a few options from a row of segments, with a raised panel that slides to the choice.

Usage

import {
  SegmentedControl,
  SegmentedControlItem,
} from 'nyctoui/segmented-control'

<SegmentedControl aria-label="View" defaultValue="list">
  <SegmentedControlItem value="list">List</SegmentedControlItem>
  <SegmentedControlItem value="board">Board</SegmentedControlItem>
</SegmentedControl>

Use it for two to five short options that switch a view or a setting. The track has the same tinted fill as secondary buttons; the checked segment sits on a raised card that slides between segments. The panel is drawn for you, so the parts are only the control and its items.

It works as a radio group: one tab stop, and the arrow keys move the choice. Each item renders a hidden native radio, so name submits the value with a form.

Good for

  • Switching a dashboard between Day, Week and Month.
  • Choosing List or Grid view in a file browser.
  • Picking Light, Dark or System in appearance settings.
  • Choosing Monthly or Yearly billing on a pricing page.

Examples

Sizes

24, 32 and 40px, the shared control heights, so it lines up with a button of the same size.

Icons

iconOnly squares a segment for a single 16px icon; give it an aria-label. An icon can also sit before the text.

In a field

A Field’s label names the control, so it needs no aria-label.

Disabled

Disable the whole control, or one item; the arrow keys skip a disabled item.

Keyboard

Tab lands on the checked segment. The arrow keys check the next or previous one and wrap at the ends; set loop={false} to stop there.

Best practices

Do
  • Use it for two to five options that should all be visible at once.
  • Give the control a label, visible or with aria-label, that says what the options choose.
  • Use iconOnly items with an aria-label each, and a tooltip when the icon alone could be read two ways.
Don’t
  • Use it for page navigation. Each segment would really be a link.
  • Use it for a plain on and off. That’s a switch.
  • Squeeze in more options than fit on a phone. Use a select.

API reference

SegmentedControl

Wraps ui-sdk’s SegmentedControl with its indicator, and takes its props, including orientation, readOnly, required and controller.

PropTypeDefault
value
The checked item’s value. Pass it to control the control.
string | null—
defaultValue
The item checked at first, when uncontrolled.
string | null—
onValueChange
Runs when the choice wants to change.
(value: string | null, details) => void—
size
Control height; matches Button and Input sizes.
'sm' | 'md' | 'lg''md'
name
The name the value submits under.
string—
disabled
Disables every item.
booleanfalse
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

SegmentedControlItem

A button with the radio role. Segments share the width equally.

PropTypeDefault
value
What the control’s value becomes when this item is checked.
string—
iconOnly
Squares the segment for one icon. Pass an aria-label.
booleanfalse
disabled
Skips the item.
booleanfalse
sx
StyleX styles merged after the built-in ones.
StyleXStyles—