Segmented
Display multiple options and allow users to select a single option.
This component is available since antd@4.20.0.
When To Use
- When displaying multiple options and user can select a single option;
- When switching the selected option, the content of the associated area changes.
Examples
- Basic ·
basic - Vertical Direction ·
vertical - Block Segmented ·
block - Round shape ·
shape - Disabled ·
disabled - Controlled mode ·
controlled - Custom Render ·
custom - Dynamic ·
dynamic - Three sizes of Segmented ·
size - With Icon ·
with-icon - With Icon only ·
icon-only - With name ·
with-name - Custom semantic dom styling ·
style-class
API
Common props ref:Common props
This component is available since
antd@4.20.0
Segmented
| Property | Description | Type | Default | Version | Global Config |
|---|---|---|---|---|---|
| block | Option to fit width to its parent's width | boolean | false | × | |
| classNames | Customize class for each semantic structure inside the Segmented component. Supports object or function. | Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string> | - | 6.0.0 | |
| defaultValue | Default selected value | string | number | Value of first item in options | × | |
| disabled | Disable all segments | boolean | false | × | |
| onChange | The callback function that is triggered when the state changes | function(value: string | number) | × | ||
| options | Set children optional | string[] | number[] | SegmentedItemType[] | [] | × | |
| orientation | Orientation | horizontal | vertical | horizontal | × | |
| size | The size of the Segmented. | large | medium | small | medium | × | |
| styles | Customize inline style for each semantic structure inside the Segmented component. Supports object or function. | Record<SemanticDOM, CSSProperties> | (info: { props }) => Record<SemanticDOM, CSSProperties> | - | 6.0.0 | |
| vertical | Orientation. Simultaneously existing with orientation, orientation takes priority | boolean | false | 5.21.0 | × |
| value | Currently selected value | string | number | × | ||
| shape | shape of Segmented | default | round | default | 5.24.0 | × |
| name | The name property of all input[type="radio"] children. if not set, it will fallback to a randomly generated name | string | 5.23.0 | × |
SegmentedItemType
| Property | Description | Type | Default | Version |
|---|---|---|---|---|
| disabled | Disabled state of segmented item | boolean | false | |
| className | The additional css class | string | - | |
| icon | Display icon for Segmented item | ReactNode | - | |
| label | Display text for Segmented item | ReactNode | - | |
| tooltip | tooltip for Segmented item | string | TooltipProps | - | |
| value | Value for Segmented item | string | number | - |
Semantic DOM
| Semantic node | Native description | Version |
|---|---|---|
root | Root element with inline-block layout, padding, background, border radius, transition and container styles | 6.0.0 |
item | Option element with relative positioning, text alignment, cursor style, transition, selected state background and hover styles | 6.0.0 |
label | Label content element with min height, line height, padding, text ellipsis and content layout styles | 6.0.0 |
icon | Icon element with icon size, color and text spacing styles | 6.0.0 |
Semantic description source: vendor/components/segmented/demo/_semantic.tsx
Design Token
Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.
| Token | Type | Native description |
|---|---|---|
itemColor | string | Text color of item |
itemHoverColor | string | Text color of item when hover |
itemHoverBg | string | Background color of item when hover |
itemActiveBg | string | Background color of item when active |
itemSelectedBg | string | Background color of item when selected |
itemSelectedColor | string | Text color of item when selected |
trackPadding | string | number | Padding of Segmented container |
trackBg | string | Background of Segmented container |
Declaration source: vendor/components/segmented/style/index.ts
import type { CSSObject } from '@ant-design/cssinjs';
import { unit } from '@ant-design/cssinjs';
import { genFocusOutline, genFocusStyle, resetComponent, textEllipsis } from '../../style';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks, mergeToken } from '../../theme/internal';
export interface ComponentToken {
/**
* @desc 选项文本颜色
* @descEN Text color of item
*/
itemColor: string;
/**
* @desc 选项悬浮态文本颜色
* @descEN Text color of item when hover
*/
itemHoverColor: string;
/**
* @desc 选项悬浮态背景颜色
* @descEN Background color of item when hover
*/
itemHoverBg: string;
/**
* @desc 选项激活态背景颜色
* @descEN Background color of item when active
*/
itemActiveBg: string;
/**
* @desc 选项选中时背景颜色
* @descEN Background color of item when selected
*/
itemSelectedBg: string;
/**
* @desc 选项选中时文字颜色
* @descEN Text color of item when selected
*/
itemSelectedColor: string;
/**
* @desc Segmented 控件容器的 padding
* @descEN Padding of Segmented container
*/
trackPadding: string | number;
/**
* @desc Segmented 控件容器背景色
* @descEN Background of Segmented container
*/
trackBg: string;
}
interface SegmentedToken extends FullToken<'Segmented'> {
segmentedPaddingHorizontal: number | string;
segmentedPaddingHorizontalSM: number | string;
}
Shared native props
Tips: The following generic properties apply to most antd components; those not supported are described separately.
| Property | Description | Type | Default |
|---|---|---|---|
| style | The additional style | CSSProperties | - |
| className | The additional css class | string | - |
| rootClassName | ClassName on the root element | string | - |
| autoFocus | Auto focus when component mounted, only effective for focusable elements like forms, links, etc. | boolean | false |
Install and reproduce an example
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23
Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.
Native type references
The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.
vendor/components/segmented/index.tsxvendor/components/segmented/style/index.ts
Source and license
https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd
Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.