enes

SegmentedControl

A compact group of segments for choosing one view or option.

Usage

<script>
  import { Label, SegmentedControl, SegmentedControlItem } from 'fluentui-svelte';
  let selectedValue = $state('day');
</script>

<Label label="View">
<SegmentedControl name="view" bind:selectedValue>
  <SegmentedControlItem value="day">Day</SegmentedControlItem>
  <SegmentedControlItem value="week">Week</SegmentedControlItem>
  <SegmentedControlItem value="month">Month</SegmentedControlItem>
</SegmentedControl>
</Label>

Arrow keys move focus; Space or Enter selects. Set selectOnFocus to select while navigating. Tab enters the selected radio. Use Label, aria-label or aria-labelledby to name the group.

Text, icons and mixed content

Use short text labels, icons with accessible names, or icons alongside text. The icon prop accepts a Fluent icon component or a Svelte snippet. Every option needs a unique value within its group.

Text only
Icons only
Text and icons

Equal widths or fit to content

Segments have equal widths by default. Set equalWidth to false to fit each segment to its content.

Equal widths
Fit content

Sizes

Choose size: small for compact rows, medium for standard controls or large when more space is available. The size is shared by every segment in the group.

Small
Medium
Large

Selection indicator

Set hideIndicator to hide the selection indicator.

Selection on focus

Arrow keys move focus without changing the selection. Enable selectOnFocus to select the focused segment.

Disabled options and groups

Disable one option to keep it visible while unavailable, or disable the whole group. Disabled radios are skipped by keyboard navigation and excluded from FormData and validation.

Disabled option
Disabled group

Using Label

Wrap SegmentedControl in Label to name the group automatically. Each option retains its own text or aria-label. An explicit aria-label or aria-labelledby on the group takes precedence. Label marks a field as required visually; set required on SegmentedControl to enable validation.

Submission, validation and reset

Set name to the field name your form expects. Only the checked enabled radio is submitted. required prevents submission until an option is selected. Reset restores the selection captured when the group was created, including an initially empty selection, and updates bind:selectedValue.

Submit the form to inspect its FormData.

External forms

Set form to the id of a form elsewhere on the page. Every radio belongs to that form and participates in its submission, validation and reset behavior.

Binding and change events

Bind selectedValue to read or update the selection. onSelectionChange receives the native change event and the new string value. Selecting the same option, updating the binding programmatically or resetting the form does not call it.

day

SegmentedControl

NameTypeDefaultDescription
ref bindableHTMLDivElement | nullThe DOM reference of the control.
selectedValue bindablestringThe value of the selected item. An empty value leaves all items unselected.
namestringThe field name shared by every radio. Defaults to a unique generated name.
formstringThe id of the form that owns the radios, when outside that form.
requiredbooleanfalseRequires a selection before the form can be submitted.
validationMessagestringCustom native validation message when a required selection is missing.
hideIndicatorbooleanfalseHides the accent indicator beneath the selected segment.
selectOnFocusbooleanfalseSelects the focused segment during arrow-key navigation.
onSelectionChange(event: Event, value: string) => voidFired when user interaction changes the selection.
size'small' | 'medium' | 'large''medium'The size of every segment.
equalWidthbooleantrueGives every segment the same width. Disable to fit each segment to its content.
disabledbooleanfalseDisables every segment.
disableTabspotbooleanfalseDisables tabspot keyboard navigation.
HTML Attributes

SegmentedControlItem

NameTypeDefaultDescription
ref bindableHTMLInputElement | nullThe DOM reference of the native radio input.
valuestringA unique value identifying this segment within its control.
iconSnippet | ComponentAn optional icon. Give icon-only items an accessible name with aria-label.
disabledbooleanfalseDisables this segment.
childrenSnippetThe content of the segment's label.
HTML Attributes
Edit this Doc View as Markdown