Skip to content

Form Components

[03] Form Components

SegmentedControl

SegmentedControl picks one option out of a few short ones shown side by side, such as a status filter or a view switch. Each segment is a native radio.

SourceEdit this page

SegmentedControl picks one option out of a few short ones that sit side by side, such as a status filter, a list or grid view, or a billing period. Each segment is a native radio inside a <label>, so a click anywhere on it selects it, the arrow keys move the selection and a form submits the value. For a long list of options, use a Select; for options that need a line of description each, use a Radio group; to move between pages, use NavLink with indicatorBottom. SegmentedControl needs @vaneui/ui 1.8.0 or later.

Basic usage

Give each SegmentedControlItem a value, and the control an aria-label or a Field label. defaultValue selects a segment without state.

<SegmentedControl aria-label="Status" defaultValue="open">
<SegmentedControlItem value="all">All</SegmentedControlItem>
<SegmentedControlItem value="open">Open</SegmentedControlItem>
<SegmentedControlItem value="closed">Closed</SegmentedControlItem>
</SegmentedControl>

The control renders role="radiogroup" on a neutral track. The selected segment is raised as a surface with a shadow, and a thin line separates two segments that are not selected.

Filter a list with a controlled value

value and onChange work as on RadioGroup: onChange receives the change event of the radio, and event.target.value is the segment's value.

Focus ring is cut off in Safari

Add a dark theme to the docs

Table header loses its color

const issues = [
{ title: 'Focus ring is cut off in Safari', status: 'open' },
{ title: 'Add a dark theme to the docs', status: 'closed' },
{ title: 'Table header loses its color', status: 'open' },
];
const [status, setStatus] = useState('all');
const shown = issues.filter(issue => status === 'all' || issue.status === status);
return (
<Col>
<SegmentedControl aria-label="Status" value={status} onChange={event => setStatus(event.target.value)}>
<SegmentedControlItem value="all">All</SegmentedControlItem>
<SegmentedControlItem value="open">Open</SegmentedControlItem>
<SegmentedControlItem value="closed">Closed</SegmentedControlItem>
</SegmentedControl>
{shown.map(issue => <Text key={issue.title}>{issue.title}</Text>)}
</Col>
);

Sizes match Button and Input

The control is sm by default, as are Button and Input, and at every size it is as tall as a Button of that size, with the same corners. The size reaches the segments, so their text, padding and icons follow it.

<Col>
{(['xs', 'sm', 'md', 'lg', 'xl'] as const).map(size => (
<Row key={size}>
<SegmentedControl {...{ [size]: true }} aria-label={`Period, ${size}`} defaultValue="week">
<SegmentedControlItem value="day">Day</SegmentedControlItem>
<SegmentedControlItem value="week">Week</SegmentedControlItem>
<SegmentedControlItem value="month">Month</SegmentedControlItem>
</SegmentedControl>
<Button {...{ [size]: true }}>Apply</Button>
</Row>
))}
</Col>

Colors and variants of the selected segment

The appearance and the variant color the selected segment, and the track stays neutral. outline, the default, raises a segment in the page color with a border in the appearance color; filled fills it with the appearance color; ghost drops the track and tints the selected segment.

<Col>
<SegmentedControl accent aria-label="View, accent outline" defaultValue="board">
<SegmentedControlItem value="list">List</SegmentedControlItem>
<SegmentedControlItem value="board">Board</SegmentedControlItem>
<SegmentedControlItem value="calendar">Calendar</SegmentedControlItem>
</SegmentedControl>
<SegmentedControl accent filled aria-label="View, accent filled" defaultValue="board">
<SegmentedControlItem value="list">List</SegmentedControlItem>
<SegmentedControlItem value="board">Board</SegmentedControlItem>
<SegmentedControlItem value="calendar">Calendar</SegmentedControlItem>
</SegmentedControl>
<SegmentedControl accent ghost aria-label="View, accent ghost" defaultValue="board">
<SegmentedControlItem value="list">List</SegmentedControlItem>
<SegmentedControlItem value="board">Board</SegmentedControlItem>
<SegmentedControlItem value="calendar">Calendar</SegmentedControlItem>
</SegmentedControl>
</Col>

A segment with its own appearance or variant keeps it, which suits a choice where each option has a meaning of its own:

<SegmentedControl filled aria-label="Result" defaultValue="passed">
<SegmentedControlItem value="passed" success>Passed</SegmentedControlItem>
<SegmentedControlItem value="failed" danger>Failed</SegmentedControlItem>
<SegmentedControlItem value="skipped">Skipped</SegmentedControlItem>
</SegmentedControl>

Shapes

rounded is the default. pill and sharp reach the track and the segments together.

<Col>
<SegmentedControl pill aria-label="Billing, pill" defaultValue="year">
<SegmentedControlItem value="month">Monthly</SegmentedControlItem>
<SegmentedControlItem value="year">Yearly</SegmentedControlItem>
</SegmentedControl>
<SegmentedControl sharp aria-label="Billing, sharp" defaultValue="year">
<SegmentedControlItem value="month">Monthly</SegmentedControlItem>
<SegmentedControlItem value="year">Yearly</SegmentedControlItem>
</SegmentedControl>
</Col>

Icons in segments

An icon takes the size of the segment's text. A segment with only an icon needs an aria-label, which goes to its radio.

<Row flexWrap>
<SegmentedControl md aria-label="Color scheme" defaultValue="light">
<SegmentedControlItem value="light"><Sun /> Light</SegmentedControlItem>
<SegmentedControlItem value="dark"><Moon /> Dark</SegmentedControlItem>
<SegmentedControlItem value="system"><Monitor /> System</SegmentedControlItem>
</SegmentedControl>
<SegmentedControl md aria-label="Layout" defaultValue="grid">
<SegmentedControlItem value="rows" aria-label="Rows"><AlignJustify /></SegmentedControlItem>
<SegmentedControlItem value="grid" aria-label="Grid"><Grid /></SegmentedControlItem>
</SegmentedControl>
</Row>

Fill the width

wFull stretches the control to the width of its container and shares it out between the segments.

<SegmentedControl wFull aria-label="Billing" defaultValue="year">
<SegmentedControlItem value="month">Monthly</SegmentedControlItem>
<SegmentedControlItem value="year">Yearly</SegmentedControlItem>
</SegmentedControl>

Disabled segments and controls

disabled on a segment dims it and the arrow keys skip it. disabled on the control dims every segment and keeps the selection.

<Col>
<SegmentedControl aria-label="Period" defaultValue="week">
<SegmentedControlItem value="day">Day</SegmentedControlItem>
<SegmentedControlItem value="week">Week</SegmentedControlItem>
<SegmentedControlItem value="month" disabled>Month</SegmentedControlItem>
</SegmentedControl>
<SegmentedControl disabled aria-label="Period, disabled" defaultValue="week">
<SegmentedControlItem value="day">Day</SegmentedControlItem>
<SegmentedControlItem value="week">Week</SegmentedControlItem>
<SegmentedControlItem value="month">Month</SegmentedControlItem>
</SegmentedControl>
</Col>

In a form or a Field

Inside a Field, the control is labelled by the Field's label and described by its help text, and it takes the Field's disabled and required. name is the key the form submits; without one the control generates a name, so its segments still act as one group.

Express arrives the next working day.

<form onSubmit={event => event.preventDefault()}>
<Col>
<Field label="Delivery" description="Express arrives the next working day.">
<SegmentedControl name="delivery" defaultValue="standard">
<SegmentedControlItem value="standard">Standard</SegmentedControlItem>
<SegmentedControlItem value="express">Express</SegmentedControlItem>
<SegmentedControlItem value="pickup">Pickup</SegmentedControlItem>
</SegmentedControl>
</Field>
<Button type="submit" filled>Continue</Button>
</Col>
</form>

Keyboard and screen readers

Tab moves the focus to the selected segment, and the arrow keys move the selection to the previous or next segment, as in any radio group. The focus ring is drawn on the segment itself, inside the track. Screen readers announce the control as a radio group with its label, and each segment as a radio button with its text and its position, such as "Open, radio button, 2 of 3".

A segment's className and style go to its <label>, so they change how the segment looks. ref, aria-label, id and the other attributes go to its radio.

Loading placeholder

skeleton on the control, or on a container around it, draws it as one solid shape of its own size until the data arrives. See Skeleton.

<SegmentedControl skeleton aria-label="Status" defaultValue="all">
<SegmentedControlItem value="all">All</SegmentedControlItem>
<SegmentedControlItem value="open">Open</SegmentedControlItem>
<SegmentedControlItem value="closed">Closed</SegmentedControlItem>
</SegmentedControl>

Customizing

SegmentedControl has two theme nodes: segmentedControl.main for the track and segmentedControl.item for the segments. Set app-wide defaults with ThemeProvider's themeDefaults. A size, appearance, variant or shape set on main reaches the segments.

<ThemeProvider themeDefaults={{ segmentedControl: { main: { md: true, pill: true }, item: { fontSemibold: true } } }}>
<SegmentedControl aria-label="Status" defaultValue="all">
<SegmentedControlItem value="all">All</SegmentedControlItem>
<SegmentedControlItem value="open">Open</SegmentedControlItem>
<SegmentedControlItem value="closed">Closed</SegmentedControlItem>
</SegmentedControl>
</ThemeProvider>

SegmentedControl Props

PropCategoryDefaultDescription
accent

Appearance

Accent color appearance (rose)

danger

Appearance

Danger color appearance (red)

info

Appearance

Info color appearance (cyan)

inheritAppearance

Appearance

Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables

primary

Appearance

✓

Primary color appearance (gray)

secondary

Appearance

Secondary color appearance (gray)

success

Appearance

Success color appearance (green)

tertiary

Appearance

Tertiary color appearance

warning

Appearance

Warning color appearance (amber)

margin

Margin

Enable margin on all sides

marginB

Margin

Enable only bottom margin

marginT

Margin

Enable only top margin

marginX

Margin

Enable only horizontal (inline) margin

marginY

Margin

Enable only vertical (block) margin

noMargin

Margin

Disable margin (reset to 0)

noPadding

Padding

Disable internal padding

padding

Padding

✓

Enable internal padding

paddingX

Padding

Enable only horizontal padding

paddingY

Padding

Enable only vertical padding

pill

Shape

Fully rounded corners (circular)

rounded

Shape

✓

Medium rounded corners (default)

sharp

Shape

No rounded corners (square)

lg

Size

Large size

md

Size

Medium size (default)

sm

Size

✓

Small size

xl

Size

Extra large size

xs

Size

Extra small size

skeleton

Skeleton

Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too

filled

Variant

Filled variant - solid background with contrasting text color

ghost

Variant

Ghost variant - transparent background, no border, appearance-colored text, tinted hover background

outline

Variant

✓

Outline variant - transparent background with border and colored text (default)

Layout & utility props (gap, padding, hide, items, justify, ...)

Documented on Common Props.

PropCategoryDefaultDescription
block

Display

Block display - takes full width, new line

contents

Display

Contents display - element's box is removed, children display as if parent didn't exist

flex

Display

Flex display - flexbox container

grid

Display

Grid display - CSS grid container

hidden

Display

Hidden display - element is not visible

inline

Display

Inline display - flows with text

inlineBlock

Display

Inline-block display - inline but with block properties

inlineFlex

Display

✓

Inline-flex display - inline flexbox container

inlineGrid

Display

Inline-grid display - inline grid container

table

Display

Table display - behaves like table element

tableCell

Display

Table-cell display - behaves like td element

desktopHide

Hide

Hide element on desktop devices and below (max-desktop: 80rem)

mobileHide

Hide

Hide element on mobile devices and below (max-mobile: 48rem)

tabletHide

Hide

Hide element on tablet devices and below (max-tablet: 64rem)

itemsBaseline

Items

Align items to baseline

itemsCenter

Items

Align items to center

itemsEnd

Items

Align items to end (bottom/right)

itemsStart

Items

Align items to start (top/left)

itemsStretch

Items

✓

Stretch items to fill container

justifyAround

Justify

Distribute items with space around them

justifyBaseline

Justify

Align items along their baseline on main axis

justifyBetween

Justify

Distribute items with space between them

justifyCenter

Justify

Center items along the main axis

justifyEnd

Justify

Pack items toward the end of the main axis

justifyEvenly

Justify

Distribute items with equal space around them

justifyStart

Justify

Pack items toward the start of the main axis

justifyStretch

Justify

Stretch items to fill the main axis

overflowAuto

Overflow

Auto overflow - show scrollbars if needed

overflowClip

Overflow

Clip overflow - hard clip without scrollbars

overflowHidden

Overflow

Hidden overflow - clip content without scrollbars

overflowScroll

Overflow

Scroll overflow - always show scrollbars

overflowVisible

Overflow

Visible overflow - content extends beyond bounds

overflowXAuto

Overflow

Auto overflow on X-axis only

overflowXClip

Overflow

Clip overflow on X-axis only

overflowXHidden

Overflow

Hidden overflow on X-axis only

overflowXScroll

Overflow

Scroll overflow on X-axis only

overflowXVisible

Overflow

Visible overflow on X-axis only

overflowYAuto

Overflow

Auto overflow on Y-axis only

overflowYClip

Overflow

Clip overflow on Y-axis only

overflowYHidden

Overflow

Hidden overflow on Y-axis only

overflowYScroll

Overflow

Scroll overflow on Y-axis only

overflowYVisible

Overflow

Visible overflow on Y-axis only

absolute

Position

Absolute positioning

fixed

Position

Fixed positioning

relative

Position

Relative positioning

static

Position

Static positioning

sticky

Position

Sticky positioning at the top edge; set --sticky-top to stick below a fixed header

desktopWFull

Responsive Width

Set width to 100% on desktop and below, below 1280px (max-desktop: 80rem)

mobileWFull

Responsive Width

Set width to 100% on mobile, below 768px (max-mobile: 48rem)

tabletWFull

Responsive Width

Set width to 100% on tablet and below, below 1024px (max-tablet: 64rem)

desktopShow

Show

Show element only on desktop and below, below 1280px (hidden from 80rem up)

mobileShow

Show

Show element only on mobile, below 768px (hidden from 48rem up)

tabletShow

Show

Show element only on tablet and below, below 1024px (hidden from 64rem up)

wAuto

Width

Set width to auto

wFit

Width

Set width to fit-content

wFull

Width

Set width to 100%

wScreen

Width

Set width to 100vw (viewport width), removes max-width constraint

SegmentedControlItem Props

PropCategoryDefaultDescription
accent

Appearance

Accent color appearance (rose)

danger

Appearance

Danger color appearance (red)

info

Appearance

Info color appearance (cyan)

inheritAppearance

Appearance

Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables

primary

Appearance

✓

Primary color appearance (gray)

secondary

Appearance

Secondary color appearance (gray)

success

Appearance

Success color appearance (green)

tertiary

Appearance

Tertiary color appearance

warning

Appearance

Warning color appearance (amber)

disabled

Disabled

Disable the component — reduces opacity, changes cursor to not-allowed, and prevents interaction

fontHeading

Font Family

Heading font family (defaults to sans, customizable via --font-heading) — emits font-heading

fontMono

Font Family

Monospace font family — emits font-mono

fontSans

Font Family

✓

Sans-serif font family (default) — emits font-sans

fontSerif

Font Family

Serif font family — emits font-serif

italic

Font Style

Italic font style

notItalic

Font Style

Not italic (normal) font style

fontBlack

Font Weight

Black font weight (900) — emits font-black

fontBold

Font Weight

Bold font weight (700) — emits font-bold

fontExtrabold

Font Weight

Extra bold font weight (800) — emits font-extrabold

fontExtralight

Font Weight

Extra light font weight (200) — emits font-extralight

fontLight

Font Weight

Light font weight (300) — emits font-light

fontMedium

Font Weight

✓

Medium font weight (500) — emits font-medium

fontNormal

Font Weight

Normal font weight (400) — emits font-normal

fontSemibold

Font Weight

Semibold font weight (600) — emits font-semibold

fontThin

Font Weight

Thin font weight (100) — emits font-thin

noPadding

Padding

Disable internal padding

padding

Padding

✓

Enable internal padding

paddingX

Padding

Enable only horizontal padding

paddingY

Padding

Enable only vertical padding

pill

Shape

Fully rounded corners (circular)

rounded

Shape

✓

Medium rounded corners (default)

sharp

Shape

No rounded corners (square)

lg

Size

Large size

md

Size

Medium size (default)

sm

Size

✓

Small size

xl

Size

Extra large size

xs

Size

Extra small size

skeleton

Skeleton

Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too

lineThrough

Text Decoration

Add strikethrough/line-through decoration across text

noUnderline

Text Decoration

Remove ALL text-decoration — underline, line-through, and overline (text-decoration: none)

overline

Text Decoration

Add overline decoration above text

underline

Text Decoration

Add underline decoration below text

capitalize

Text Transform

Capitalize first letter of each word

lowercase

Text Transform

Transform text to lowercase

normalCase

Text Transform

Normal text case (no transformation)

uppercase

Text Transform

Transform text to uppercase

filled

Variant

Filled variant - solid background with contrasting text color

ghost

Variant

Ghost variant - transparent background, no border, appearance-colored text, tinted hover background

outline

Variant

✓

Outline variant - transparent background with border and colored text (default)

Layout & utility props (gap, padding, hide, items, justify, ...)

Documented on Common Props.

PropCategoryDefaultDescription
cursorDefault

Cursor

Default cursor - standard arrow

cursorMove

Cursor

Move cursor - indicates draggable element

cursorNone

Cursor

No cursor - hides the cursor

cursorNotAllowed

Cursor

Not-allowed cursor - indicates disabled state

cursorPointer

Cursor

✓

Pointer cursor - indicates clickable element

cursorText

Cursor

Text cursor - indicates selectable text

cursorWait

Cursor

Wait cursor - indicates loading/processing

block

Display

Block display - takes full width, new line

contents

Display

Contents display - element's box is removed, children display as if parent didn't exist

flex

Display

Flex display - flexbox container

grid

Display

Grid display - CSS grid container

hidden

Display

Hidden display - element is not visible

inline

Display

Inline display - flows with text

inlineBlock

Display

Inline-block display - inline but with block properties

inlineFlex

Display

✓

Inline-flex display - inline flexbox container

inlineGrid

Display

Inline-grid display - inline grid container

table

Display

Table display - behaves like table element

tableCell

Display

Table-cell display - behaves like td element

gap

Gap

✓

Enable gap spacing between children, at the component's size

gapLg

Gap

Large gap, whatever the component's size

gapMd

Gap

Medium gap, whatever the component's size

gapSm

Gap

Small gap, whatever the component's size

gapXl

Gap

Extra-large gap, whatever the component's size

gapXs

Gap

Extra-small gap, whatever the component's size

noGap

Gap

Disable gap spacing

desktopHide

Hide

Hide element on desktop devices and below (max-desktop: 80rem)

mobileHide

Hide

Hide element on mobile devices and below (max-mobile: 48rem)

tabletHide

Hide

Hide element on tablet devices and below (max-tablet: 64rem)

itemsBaseline

Items

Align items to baseline

itemsCenter

Items

✓

Align items to center

itemsEnd

Items

Align items to end (bottom/right)

itemsStart

Items

Align items to start (top/left)

itemsStretch

Items

Stretch items to fill container

justifyAround

Justify

Distribute items with space around them

justifyBaseline

Justify

Align items along their baseline on main axis

justifyBetween

Justify

Distribute items with space between them

justifyCenter

Justify

✓

Center items along the main axis

justifyEnd

Justify

Pack items toward the end of the main axis

justifyEvenly

Justify

Distribute items with equal space around them

justifyStart

Justify

Pack items toward the start of the main axis

justifyStretch

Justify

Stretch items to fill the main axis

overflowAuto

Overflow

Auto overflow - show scrollbars if needed

overflowClip

Overflow

Clip overflow - hard clip without scrollbars

overflowHidden

Overflow

Hidden overflow - clip content without scrollbars

overflowScroll

Overflow

Scroll overflow - always show scrollbars

overflowVisible

Overflow

Visible overflow - content extends beyond bounds

overflowXAuto

Overflow

Auto overflow on X-axis only

overflowXClip

Overflow

Clip overflow on X-axis only

overflowXHidden

Overflow

Hidden overflow on X-axis only

overflowXScroll

Overflow

Scroll overflow on X-axis only

overflowXVisible

Overflow

Visible overflow on X-axis only

overflowYAuto

Overflow

Auto overflow on Y-axis only

overflowYClip

Overflow

Clip overflow on Y-axis only

overflowYHidden

Overflow

Hidden overflow on Y-axis only

overflowYScroll

Overflow

Scroll overflow on Y-axis only

overflowYVisible

Overflow

Visible overflow on Y-axis only

absolute

Position

Absolute positioning

fixed

Position

Fixed positioning

relative

Position

✓

Relative positioning

static

Position

Static positioning

sticky

Position

Sticky positioning at the top edge; set --sticky-top to stick below a fixed header

desktopShow

Show

Show element only on desktop and below, below 1280px (hidden from 80rem up)

mobileShow

Show

Show element only on mobile, below 768px (hidden from 48rem up)

tabletShow

Show

Show element only on tablet and below, below 1024px (hidden from 64rem up)

noTransition

Transition

Disable transitions for instant state changes

transition

Transition

✓

Enable smooth transitions between states

whitespaceBreakSpaces

Whitespace

Preserve whitespace incl. trailing spaces, wrap text (white-space: break-spaces)

whitespaceNormal

Whitespace

Normal wrapping - default browser behavior

whitespaceNowrap

Whitespace

✓

No wrap - text stays on single line

whitespacePre

Whitespace

Preserve whitespace and line breaks

whitespacePreLine

Whitespace

Preserve line breaks, collapse spaces, wrap text

whitespacePreWrap

Whitespace

Preserve whitespace, wrap text