VOOZH about

URL: https://ant.design/components/segmented/

⇱ Segmented - Ant Design


QRCodeStatistic
👁 loading

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

API

Common props ref:Common props

This component is available since antd@4.20.0

Segmented

PropertyDescriptionTypeDefaultVersionGlobal Config
blockOption to fit width to its parent's widthbooleanfalse×
classNamesCustomize class for each semantic structure inside the Segmented component. Supports object or function.Record<SemanticDOM, string> | (info: { props }) => Record<SemanticDOM, string>-6.0.0
defaultValueDefault selected valuestring | numberValue of first item in options×
disabledDisable all segmentsbooleanfalse×
onChangeThe callback function that is triggered when the state changesfunction(value: string | number)×
optionsSet children optionalstring[] | number[] | SegmentedItemType[][]×
orientationOrientationhorizontal | verticalhorizontal×
sizeThe size of the Segmented.large | medium | smallmedium×
stylesCustomize 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
verticalOrientation. Simultaneously existing with orientation, orientation takes prioritybooleanfalse5.21.0×
valueCurrently selected valuestring | number×
shapeshape of Segmenteddefault | rounddefault5.24.0×
nameThe name property of all input[type="radio"] children. if not set, it will fallback to a randomly generated namestring5.23.0×

SegmentedItemType

PropertyDescriptionTypeDefaultVersion
disabledDisabled state of segmented itembooleanfalse
classNameThe additional css classstring-
iconDisplay icon for Segmented itemReactNode-
labelDisplay text for Segmented itemReactNode-
tooltiptooltip for Segmented itemstring | TooltipProps-
valueValue for Segmented itemstring | number-

Semantic DOM

Design Token

Component TokenHow to use?
Token NameDescriptionTypeDefault Value
itemActiveBgBackground color of item when activestringrgba(0,0,0,0.15)
itemColorText color of itemstringrgba(0,0,0,0.65)
itemHoverBgBackground color of item when hoverstringrgba(0,0,0,0.06)
itemHoverColorText color of item when hoverstringrgba(0,0,0,0.88)
itemSelectedBgBackground color of item when selectedstring#ffffff
itemSelectedColorText color of item when selectedstringrgba(0,0,0,0.88)
trackBgBackground of Segmented containerstring#f5f5f5
trackPaddingPadding of Segmented containerstring | number2
Global TokenHow to use?
Token NameDescriptionTypeDefault Value
colorPrimaryBorderThe stroke color under the main color gradient, used on the stroke of components such as Slider.string#91caff
colorTextDefault text color which comply with W3C standards, and this color is also the darkest neutral color.stringrgba(0,0,0,0.88)
colorTextDisabledControl the color of text in disabled state.stringrgba(0,0,0,0.25)
borderRadiusBorder radius of base componentsnumber6
borderRadiusLGLG size border radius, used in some large border radius components, such as Card, Modal and other components.number8
borderRadiusSMSM size border radius, used in small size components, such as Button, Input, Select and other input components in small sizenumber4
borderRadiusXSXS size border radius, used in some small border radius components, such as Segmented, Arrow and other components with small border radius.number2
boxShadowTertiaryControl the tertiary box shadow style of an element.string 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)
controlHeightThe height of the basic controls such as buttons and input boxes in Ant Designnumber32
controlHeightLGLG component heightnumber40
controlHeightSMSM component heightnumber24
controlPaddingHorizontalControl the horizontal padding of an element.number12
controlPaddingHorizontalSMControl the horizontal padding of an element with a small-medium size.number8
fontFamilyThe font family of Ant Design prioritizes the default interface font of the system, and provides a set of alternative font libraries that are suitable for screen display to maintain the readability and readability of the font under different platforms and browsers, reflecting the friendly, stable and professional characteristics.string-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'
fontSizeThe most widely used font size in the design system, from which the text gradient will be derived.number14
fontSizeLGLarge font sizenumber16
lineHeightLine height of text.number1.5714285714285714
lineWidthBorder width of base componentsnumber1
lineWidthFocusControl the width of the line when the component is in focus state.number3
marginSMControl the margin of an element, with a medium-small size.number12
motionDurationMidMotion speed, medium speed. Used for medium element animation interaction.string0.2s
motionDurationSlowMotion speed, slow speed. Used for large element animation interaction.string0.3s
motionEaseInOutPreset motion curve.string
cubic-bezier(0.645, 0.045, 0.355, 1)
paddingXXSControl the extra extra small padding of the element.number4
Basic

The most basic usage.

Block Segmented

block property will make the Segmented fit to its parent width.

Disabled

Disabled Segmented.

Custom Render

Custom each Segmented Item.

Three sizes of Segmented

There are three sizes of a Segmented component: large (40px), medium (32px), and small (24px).

With Icon only

Set icon without label for Segmented Item.

You can customize the semantic dom style of the Segmented by passing objects/functions through classNames and styles.

6.0.0

Make it vertical.

5.21.0

Round shape of Segmented.

5.24.0
Controlled mode

Controlled Segmented.

Dynamic

Load options dynamically.

With Icon

Set icon for Segmented Item.

Passing the name property to all input[type="radio"] that are in the same Segmented. It is usually used to let the browser see your Segmented as a real "group" and keep the default behavior. For example, using left/right keyboard arrow to change your selection that in the same Segmented.

5.23.0
  • root
    6.0.0
    Root element with inline-block layout, padding, background, border radius, transition and container styles
  • item
    6.0.0
    Option element with relative positioning, text alignment, cursor style, transition, selected state background and hover styles
  • label
    6.0.0
    Label content element with min height, line height, padding, text ellipsis and content layout styles
  • icon
    6.0.0
    Icon element with icon size, color and text spacing styles