Back to Ant Design

Segmented

components/segmented/index.en-US.md

6.3.73.5 KB
Original Source

This component is available since [email protected].

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

<!-- prettier-ignore -->

<code src="./demo/basic.tsx">Basic</code> <code src="./demo/vertical.tsx" version="5.21.0">Vertical Direction</code> <code src="./demo/block.tsx">Block Segmented</code> <code src="./demo/shape.tsx" version="5.24.0">Round shape</code> <code src="./demo/disabled.tsx">Disabled</code> <code src="./demo/controlled.tsx">Controlled mode</code> <code src="./demo/custom.tsx">Custom Render</code> <code src="./demo/dynamic.tsx">Dynamic</code> <code src="./demo/size.tsx">Three sizes of Segmented</code> <code src="./demo/with-icon.tsx">With Icon</code> <code src="./demo/icon-only.tsx">With Icon only</code> <code src="./demo/with-name.tsx" version="5.23.0">With name</code> <code src="./demo/style-class.tsx" version="6.0.0">Custom semantic dom styling</code> <code src="./demo/controlled-two.tsx" debug>Controlled Synced mode</code> <code src="./demo/size-consistent.tsx" debug>Consistent height</code> <code src="./demo/componentToken.tsx" debug>Custom component token</code>

API

Common props ref:Common props

This component is available since [email protected]

PropertyDescriptionTypeDefaultVersion
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>-
defaultValueDefault selected valuestring | number
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>-
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

<code src="./demo/_semantic.tsx" simplify="true"></code>

Design Token

<ComponentTokenTable component="Segmented"></ComponentTokenTable>