JGuang

Segmented

Segmented · Ant Design Mobile

Preview
npm install antd-mobile@5.43.0

Segmented

This component is available since antd-mobile@5.38.0.

Install

npm install antd-mobile@5.43.0

antd-mobile is for mobile web, not React Native or Mini Programs. React 19 projects must register createRoot with unstableSetRender at the entry, or imperative APIs such as Toast and Dialog cannot render. Switch dark mode with <html data-prefers-color-scheme="dark">.

Examples come from the official Ant Design Mobile repository (MIT) at the commit published as npm 5.43.0. Presentation helpers such as DemoBlock are JGuang rewrites, not antd-mobile APIs.

This component is available since antd-mobile@5.38.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.

Demos

Segmented

Props

PropertyDescriptionTypeDefault
blockOption to fit width to its parent's widthbooleanfalse
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[][]
valueCurrently selected valuestring | number

SegmentedItemType

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

CSS Variables

NameDescriptionDefault
NameDescriptionDefault
----------------------------------------------------------------
--segmented-backgroundBackground colorvar(--adm-color-fill-content)
--segmented-item-colorText color of segment itemvar(--adm-color-text-secondary)
--segmented-item-selected-backgroundBackground color of selected segmentvar(--adm-color-background)
--segmented-item-selected-colorText color of selected segment itemvar(--adm-color-text)
--segmented-item-disabled-colorText color of disabled segment itemvar(--adm-color-weak)