Segmented Control

Switches between a few mutually exclusive views or modes.

Configurations

Supported configurations for this component.

Configurations

5 examples
Live
Labels
sm
md
lg
Icons
sm
md
lg
Icon and label
sm
md
lg
Last selected
sm
md
lg

Add to your project

One command adds this component to your project.

1

Run the following command. New project? Run npx shadcn@latest init first to set up Tailwind and path aliases.

npx shadcn@latest add @aicanvas/••••••••••••

Light and dark both come with the install and follow the dark class on <html>, the shadcn dark mode setup (next-themes with attribute="class").

Props

Every prop this component accepts. Any other prop is forwarded to the underlying element.

SegmentOption

PropTypeDefaultDescription
valuereqstring-Unique value that identifies this segment.
labelstring-Text shown on the segment.
iconReact.ComponentType<{ size?: number, weight?: string }>-Icon component rendered in the segment, optionally alongside its label.
ariaLabelstring-Accessible name for the segment, falling back to label when omitted.

SegmentedControl

PropTypeDefaultDescription
valuereqstring-Value of the currently selected segment.
onChangereq(next: string) => void-Handler called with the value of the newly selected segment.
optionsreqSegmentOption[]-Segments to render, in display order.
ariaLabelreqstring-Accessible name for the tablist; required when no surrounding label names the control.
size'sm'|'md'|'lg''md'Height and icon-size preset for the control.
layoutGroupIdstring-Override the auto-generated per-instance id only when you explicitly want two SegmentedControls to share their indicator (animating across both as one unit). The default `useId()` value scopes the indicator to a single control, which is what you want 99% of the time, without it, switching selections in one control makes the indicator fly between controls.
classNamestring-Extra classes merged onto the root element.
styleReact.CSSProperties-Inline styles merged onto the root element.

More Andromeda Pro components