Segmented
One selected option to switch period or view.
When to use
Segmented selects one value for an already existing area: report period, list view, or map layer. All options are visible at once, and toggling changes the view or options of that area. For individual content panels use Tabs, for regular form selection use Radio.
Limit the set to understandable options that can be conveniently compared side by side. The caption explains the result of the switch. Application example changes the report total when selecting a period.
Select value
The options property accepts strings, numbers, or objects with separate value and label. The model retains the value type: the number 0 is different from the string '0'. The label and icon do not change the type of the selected value.
| Problem | Setting | Example |
|---|---|---|
| Link local selection | bind:value, options |
Basic selection |
| Manage choice externally | value, onChange |
Guided Choice |
| Save number in model | Numeric value |
Group name and numeric value |
| Update Option Set | New options and valid value |
Dynamic options |
The defaultValue property specifies the initial local value; without it, the first option options is used. Subsequent changes to defaultValue do not reinitialize the control. For changes and resets, update value or the state associated via bind:value.
The onChange handler reports the new value upon user selection. Selecting the current option again does not change it, and an external assignment to value is not considered a user event. Guided Example separately counts the selection and returns the state of the external button.
Changing options does not automatically select a replacement. When deleting the current option, the application must simultaneously assign a valid value. disabled disables the entire group or individual variant without turning it into a different model value.
Signatures and location
The label can be a string, a number, or a Svelte snippet; icon accepts snippet. Your signatures combines the Avatar and name, while icon with text keeps the regular caption next to the SVG.
For the option with only an icon, set aria-label; tooltip or title provide additional explanation. Don't rely on the drawing as the only name available. Example of icons shows captions and individual Tooltip.
The block property stretches the group to the available width. orientation specifies horizontal or vertical orientation and takes precedence over vertical. shape=round changes shape; size selects small/medium/large, without a local value the overall size of the components is valid. Size examples and full width show these settings separately.
classNames and CSS styles strings for root, item, label and icon are available for decoration - an object or a function from props. Semantic slots show the current settings. The theme.components.Segmented component design tokens are applied to the skin; token section describes the available options.
A non-empty local prefixCls specifies the full CSS prefix of the root, variants, and indicator. The empty string and undefined inherit ConfigProvider.prefixCls with the -segmented suffix, defaulting to ant-segmented. CSS variables and the common marker preserve names. Example ConfigProvider toggles global and local prefix while maintaining radio DOM, selection and focus. Changing classes does not itself trigger onChange.
Keyboard and form
Options use native radios with a common name. Without an explicit name, Segmented creates its own. Tab moves focus in and out of the group; the arrows change the selection, skipping unavailable options and moving through the end of the list. Give the group an accessible name, as in the basic example.
Indicator movement does not create a separate selection event; with prefers-reduced-motion it is disabled. The application works with value and onChange, not the end of the CSS animation. To access the root after mount, bind:nativeElement is provided; There is no separate API instance.
In the current package, the native input does not receive a value variant, so FormData returns the string on rather than the selected string or number. name concatenates radio, but does not provide the required serialization. Priority example sends a number from the Svelte state, preserving its original type.
Examples
Basic selection
Strings in options and bind:value. The value next to it reflects the selected period.
<script lang="ts">
import { Segmented } from '@woodger/antd';
let value = $state("Week");
</script>
<Segmented aria-label={("Base period")} options={([
"Day",
"Week",
"Month"
])} bind:value />
<p><output aria-label={("Selected period")}>{(value)}</output></p>
Vertical direction
orientation="vertical" arranges the options from top to bottom. Compatible vertical is also supported.
<script lang="ts">
import { Segmented } from '@woodger/antd';
</script>
<Segmented aria-label={("Vertical view")} orientation="vertical" options={(["Map", "Routes", "Satellite"])} />
Full width
block stretches the group and distributes the available width between options.
<script lang="ts">
import { Segmented } from '@woodger/antd';
</script>
<Segmented aria-label={("Full width view")} block options={([
"List",
"Board",
"Calendar"
])} />
Rounded shape
shape="round" changes the shape of the group and the selected option.
<script lang="ts">
import { Segmented } from '@woodger/antd';
</script>
<Segmented aria-label={("Rounded period")} shape="round" options={([
"Day",
"Week",
"Month"
])} />
Unavailable options
Blocking the entire group and a specific month. The keyboard skips an unavailable option.
<script lang="ts">
import { Segmented } from '@woodger/antd';
</script>
<style>
.examples {
display: grid;
justify-items: start;
gap: 16px;
}
</style>
<div class="examples">
<Segmented aria-label={("Inaccessible group")} disabled options={([
"Day",
"Week",
"Month"
])} />
<Segmented aria-label={("Unavailable month")} options={([
"Day",
"Week",
{ value: "Month", label: "Month", disabled: true }
])} />
</div>
Guided selection
value/onChange and external action. The counter changes only when the user selects a new value.
<script lang="ts">
import { Button, Segmented, type SegmentedOption } from '@woodger/antd';
type View = 'list' | 'board';
const options: SegmentedOption<View>[] = [
{ value: 'list', label: "List" },
{ value: 'board', label: "Board" }
];
let value = $state<View>('list');
let changes = $state(0);
function handleChange(next: View) {
value = next;
changes += 1;
}
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
}
</style>
<div class="controls">
<Segmented aria-label={("Controlled view")} options={(options)}
{value} onChange={handleChange} />
<Button onclick={() => { value = 'list'; }}>{("Return list")}</Button>
</div>
<p>
<output aria-label={("Controlled view status")}>{value}{("; changes: ")}{changes}</output>
</p>
Your labels
Svelte snippets replace ReactNode: Avatar and name form one available variant label.
<script lang="ts">
import { Avatar, Segmented } from '@woodger/antd';
</script>
<style>.person {
display: grid;
justify-items: center;
gap: 6px;
padding: 8px 12px;
line-height: 1.5;
}</style>
{#snippet anna()}<div
class="person"
><Avatar
style="background:#722ed1"
>{("A")}</Avatar><span>{("Anna")}</span></div>{/snippet}
{#snippet boris()}<div
class="person"
><Avatar
style="background:#d46b08"
>{("B")}</Avatar><span>{("Boris")}</span></div>{/snippet}
<Segmented aria-label={("Responsible")} options={([
{ value: 'anna', label: anna, 'aria-label': "Anna" },
{ value: 'boris', label: boris, 'aria-label': "Boris" }
])} />
Dynamic options
Adding a quarter and year maintains the current selection.
<script lang="ts">
import { Button, Segmented } from '@woodger/antd';
let extended = $state(false);
let value = $state("Day");
const initial = ["Day", "Week", "Month"];
</script>
<Segmented aria-label={("Dynamic periods")} options={(extended ? [
...initial,
"Quarter",
"Year"
] : initial)} bind:value />
<p>
<Button disabled={extended} onclick={() => { extended = true; }}>
{("Add periods")}
</Button>
</p>
<p><output aria-label={("Dynamic period")}>{(value)}</output></p>
large
medium
small
Three sizes
large, medium and small. Without size, the size from the general settings is used.
<script lang="ts">
import { Segmented } from '@woodger/antd';
const sizes = ['large', 'medium', 'small'] as const;
</script>
<style>
.examples {
display: grid;
gap: 16px;
}
p {
margin: 0 0 8px;
}
</style>
<div class="examples">
{#each sizes as size (size)}
<div><p>{(size)}</p><Segmented aria-label={("Size Segmented " + String((size)) + "")} {size} options={(["Day", "Week", "Month"])} /></div>
{/each}
</div>
Icon and label
icon accepts Svelte snippet with SVG; label remains a regular string.
<script lang="ts">
import { Segmented } from '@woodger/antd';
</script>
{#snippet list()}<svg
width="14"
height="14"
viewBox="0 0 16 16"
fill="none"
><path
d="M5 4h9M5 8h9M5 12h9M2 4h.01M2 8h.01M2 12h.01"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
/></svg>{/snippet}
{#snippet board()}<svg
width="14"
height="14"
viewBox="0 0 16 16"
fill="none"
><path
d="M2 2h5v12H2zM9 2h5v8H9z"
stroke="currentColor"
stroke-width="1.5"
/></svg>{/snippet}
<Segmented aria-label={("View with icons")} options={([{
value: 'list',
label: "List",
icon: list
}, { value: 'board', label: "Board", icon: board }])} />
Icons only
Options have aria-label and separate Tooltip. The available name is saved without visible text.
<script lang="ts">
import { Segmented } from '@woodger/antd';
</script>
{#snippet list()}<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
><path
d="M2 4h12M2 8h12M2 12h12"
stroke="currentColor"
stroke-width="1.5"
/></svg>{/snippet}
{#snippet grid()}<svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
><path
d="M2 2h4v4H2zM10 2h4v4h-4zM2 10h4v4H2zM10 10h4v4h-4z"
stroke="currentColor"
stroke-width="1.5"
/></svg>{/snippet}
<Segmented aria-label={("Icons only")} options={([
{ value: 'list', icon: list, 'aria-label': "List", tooltip: "Show list" },
{ value: 'grid', icon: grid, 'aria-label': "Tiles", tooltip: "Show tiles" }
])} />
Group name and numeric value
name combines native radio. The form submits a number from the Svelte state; automatic radio serialization is not used.
<script lang="ts">
import { Button, Segmented } from '@woodger/antd';
let value = $state<number>(1);
let submitted = $state<number | null>(null);
function handleSubmit(event: SubmitEvent) {
event.preventDefault();
submitted = value;
}
</script>
<form onsubmit={handleSubmit}>
<Segmented aria-label={("Task priority")} name="priority" options={([
{ value: 1, label: "Regular" }, { value: 2, label: "High" }
])} bind:value />
<p><Button htmlType="submit">{("Apply priority")}</Button></p>
</form>
<p><output aria-label={("Sent priority")}>{(submitted === null ? "Not sent" : `${submitted} (${typeof submitted})`)}</output></p>
Semantic slots
The classNames object and the styles function style the real root, item, label and icon. The styles values are CSS strings.
<script lang="ts">
import { Segmented } from '@woodger/antd';
</script>
{#snippet list()}<span>≡</span>{/snippet}
{#snippet board()}<span>▤</span>{/snippet}
<Segmented aria-label={("Semantic slots design")} options={([
{ value: 'list', label: "List", icon: list }, { value: 'board', label: "Board", icon: board }
])} classNames={{ label: 'documented-segment-label' }} styles={({ props }) => ({
root: `
border: 1px dashed var(--ant-color-primary);
padding: 6px;
`,
item: props.disabled ? 'opacity:0.5' : '',
label: 'font-weight:600',
icon: 'color:var(--ant-color-primary)'
})} />
Completed tasks: 58
Report period
Applied example from the review saved: choosing a period changes the summary of the report; week contains Tooltip.
<script lang="ts">
import { Segmented, type SegmentedValue } from '@woodger/antd';
let period = $state<SegmentedValue>('week');
const totals: Record<string, number> = { day: 12, week: 58, month: 211 };
</script>
<Segmented
aria-label={("Report period")}
options={([
{ value: 'day', label: "Day" },
{ value: 'week', label: "Week", tooltip: "Indicators for the last seven days" },
{ value: 'month', label: "Month" }
])}
bind:value={period}
/>
<p>{("Completed tasks: ")}<strong>{(totals[String(period)])}</strong></p>
API
All 13 Segmented live page example themes on ant.design are mapped to the cards above. An additional card saves the report from the review. The table describes the installed SegmentedProps; full types belong to the package.
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full local CSS prefix for root, variants and indicator. The empty string inherits the common prefix; without configuration, ant-segmented is used. Changing classes saves the radio and the selected value. | string | ConfigProvider + -segmented |
options | Strings, numbers or objects with value, label, icon, disabled, tooltip, class, title and aria-label. | readonly (Value | SegmentedOption<Value>)[] | Mandatory |
value | Current value. Supports bind:value; the number type is preserved. | Value extends string | number | undefined |
defaultValue | Initial local value, read once. Changing defaultValue later does not reset the selection. | Value | First option |
onChange | Called when another available option is selected. An external assignment to value does not trigger a callback. | (value: Value) => void | — |
disabled | Blocks the entire group. A separate option is disabled via options[].disabled. | boolean | false |
block | Stretches the group and options to the width of the parent. | boolean | false |
size | large - 40 px, medium - 32 px, small - 24 px at standard density. | large | medium | small | From ConfigProvider |
orientation | Layout direction. Takes precedence over compatible vertical. | horizontal | vertical | horizontal |
vertical | Compatible name for vertical mode. | boolean | false |
shape | Regular or rounded shape. | default | round | default |
name | Common name for native radio. Does not replace the available group name. | string | Generated name |
classNames | Classes root, item, label and icon. The class of an individual option is specified via option.class, not className. | SegmentedSemanticSlots | (info) => SegmentedSemanticSlots | — |
styles | CSS lines for the same slots. The function receives info.props. | SegmentedSemanticSlots | (info) => SegmentedSemanticSlots | — |
nativeElement | bind:nativeElement returns the root div after mount; The component does not export individual focus()/blur(). | HTMLDivElement | — |
Unlike React, label and icon accept Svelte snippets, styles accept CSS strings, and the variant class is called class. There is no separate ConfigProvider.segmented in the current package. The general componentSize and direction apply.
Semantic DOM
Group - a div with the role radiogroup, aria-orientation and an available name. Each option is a label with input type="radio". For a group, use aria-label or aria-labelledby; For icons without text, set options[].aria-label.
| Slot | Element |
|---|---|
root | Root div of the group. |
item | label of each option. |
label | Label container inside label. |
icon | span icons with aria-hidden. |
Arrows on the radio switch between available options, moving through the end of the list. The native input receives focus. For programmatic focus bind:nativeElement; There is no separate API instance. Indicator movement is disabled with prefers-reduced-motion.
Registration tokens
Eight component tokens checked against ant.design and ComponentTokenMap['Segmented']. theme.components.Segmented applies component tokens to styles. Specify local design via styles, as in example semantic slots.
| Token | Purpose |
|---|---|
itemActiveBg | Background of the clicked option. |
itemColor | Option text color. |
itemHoverBg | Background when hovering. |
itemHoverColor | Text color when hovering. |
itemSelectedBg | Background of the selected option. |
itemSelectedColor | The color of the selected text. |
trackBg | Group background. |
trackPadding | Group indent. |
Common tokens of the current topic
The list is checked against the Segmented table on ant.design. The values are read reactively via theme.useToken().
| Token | Current value |
|---|---|
colorPrimaryBorder | #adc6ff |
colorText | rgba(0,0,0,0.88) |
colorTextDisabled | rgba(0,0,0,0.25) |
borderRadius | 6 |
borderRadiusLG | 8 |
borderRadiusSM | 4 |
borderRadiusXS | 2 |
boxShadowTertiary |
0 1px 2px 0 rgba(0,0,0,0.05),
0 1px 6px -1px rgba(0,0,0,0.03),
0 2px 4px 0 rgba(0,0,0,0.03)
|
controlHeight | 32 |
controlHeightLG | 40 |
controlHeightSM | 24 |
controlPaddingHorizontal | 12 |
controlPaddingHorizontalSM | 8 |
fontFamily | -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
'Noto Color Emoji' |
fontSize | 14 |
fontSizeLG | 16 |
lineHeight | 1.5714285714285714 |
lineWidth | 1 |
lineWidthFocus | 3 |
marginSM | 12 |
motionDurationMid | 0.2s |
motionDurationSlow | 0.3s |
motionEaseInOut | cubic-bezier(0.645, 0.045, 0.355, 1) |
paddingXXS | 4 |
FAQ
How is Segmented different from Tabs?
Segmented selects a value for an existing area: period, sort, or view. Tabs organizes individual content panels and their navigation.
How to get a number instead of a string?
Pass numeric value and typed state as in priority example. label does not define the type of the value.
Is name enough to submit an HTML form?
No, in the current package the native input does not receive the value option: FormData will return the standard on. Read the selection from bind:value or onChange, as in the example form. name is needed for radio grouping.
What happens when you delete the selected option?
Dynamic options do not automatically select replacements. The application must assign a valid value when deleting the current variant. Example of dynamic options shows adding without resetting selection.