Skip to the content

Option

Option is a segmented control: a track of equal cells where one is selected. Picking a cell changes one value and nothing else — no panel swaps underneath. It is controlled: you own value and update it from onChange.
Forms

When to use

Use when
  • Choosing one of two to five short options: side (buy / sell), period (1D / 1W / 1M), a percentage.
  • The choice sets a value — a form field, a filter, a chart range.
Avoid when
  • The selection swaps a content panel — use Tabs.
  • Options are long, many or need descriptions — use Radio or Select.
  • Several options can be on at once — use Checkbox.

Usage

const [side, setSide] = useState('buy');

<Option
  label="Side"
  value={side}
  onChange={setSide}
  options={[
    { value: 'buy', label: 'Buy' },
    { value: 'sell', label: 'Sell' },
  ]}
/>;

Size and width

size="small" is the chip row under an input; medium (default) stands alone. A cell can be disabled. fullWidth (default) stretches the track into equal cells; fullWidth={false} sizes it to its content.

<Option size="small" label="Percent of balance" value={pct} onChange={setPct} options={percentOptions} />
<Option fullWidth={false} label="Range" value={range} onChange={setRange} options={rangeOptions} />

Icon-only cells

A view switch shows icons alone. Name each cell with ariaLabel — it becomes the radio's accessible name and tooltip.

<Option
  fullWidth={false}
  label="View"
  value={view}
  onChange={setView}
  options={[
    { value: 'cards', label: <Icon icon={grid} />, ariaLabel: 'Cards' },
    { value: 'list', label: <Icon icon={listView} />, ariaLabel: 'List' },
  ]}
/>

Accessibility

  • The track is a radiogroup; each cell is a radio with aria-checked.
  • Tab lands on the selected cell; arrow keys move the selection, wrapping and skipping disabled cells; Home and End jump to the ends.
  • Name the group with label, or aria-labelledby when a visible label exists. Icon-only cells need ariaLabel.
  • Keyboard focus stays visible in forced-colors mode.

Properties

The track also accepts the layout props of a Flex.

See also