Examples

Basic

Preview
Example.tsx
import { SegmentedControl } from '@reactloom/ui';

export default function Example() {
  return (
    <SegmentedControl
      aria-label="Date range"
      defaultValue="30d"
      options={[
        { value: '24h', label: '24 hours' },
        { value: '7d', label: '7 days' },
        { value: '30d', label: '30 days' },
        { value: '12m', label: '12 months' },
      ]}
    />
  );
}

Full width

Preview
Example.tsx
import { SegmentedControl } from '@reactloom/ui';

export default function Example() {
  return (
    <div style={{ width: '100%', maxWidth: 420 }}>
      <SegmentedControl
        aria-label="Billing"
        fullWidth
        defaultValue="annual"
        options={[
          { value: 'monthly', label: 'Monthly' },
          { value: 'annual', label: 'Annual' },
          { value: 'custom', label: 'Custom', disabled: true },
        ]}
      />
    </div>
  );
}

API reference

SegmentedControl props
PropTypeDefault
optionsrequired
{ value, label, disabled? }[]—
aria-label
Required: what the choice is about.
string—
value / defaultValue
Defaults to the first option.
string—
onValueChange
(value: string) => void—
size
'sm' | 'md' | 'lg''md'
fullWidth
booleanfalse
name
Generated when omitted.
string—

Customization

Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[data-full-width]present when on
[data-size]sm · md · lg

Theme tokens it reads

--pl-color-bg-muted --pl-color-bg-surface --pl-color-border-input --pl-color-fg-default --pl-color-fg-disabled --pl-color-fg-muted --pl-control-height-lg --pl-control-height-md --pl-control-height-sm --pl-focus-ring-color --pl-focus-ring-width --pl-font-size-lg --pl-font-size-md --pl-font-size-sm --pl-radius-md --pl-shadow-xs

Accessibility

  • The selected segment is marked by a ring that meets 3:1 contrast — not only by a background tint.
  • Built on native radios, so it submits with forms. Arrow keys behave the same in every browser: they wrap at the ends, skip disabled segments and follow the reading direction (← moves to the next segment in right-to-left layouts). Safari’s native radios would stop at the ends and not mirror; ReactLoom handles the keys itself.
Keyboard interactions
KeyAction
TabFocus the selected segment
← / →Select the previous / next segment (mirrored in right-to-left layouts; wraps at the ends)
↑ / ↓Select the previous / next segment

Usage guidelines

Do

  • Keep it to 2–5 short options.

Don’t

  • Don’t use it for navigation between pages — that is Tabs (Phase 2).