JGuang

Selector

Selector · Ant Design Mobile

Preview
npm install antd-mobile@5.43.0

Selector

Select one or more from a set of options.

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.

Select one or more from a set of options.

When to Use

Provides multiple options for the user to choose from, typically used in filters and forms.

Demos

Selector

Props

NameDescriptionTypeDefault
columnsNumber of the displayed columns (Note that grid layout not support in IOS 9)number-
defaultValueSelected value by defaultSelectorValue[][]
disabledWhether to all disable selectingbooleanfalse
fieldNamesCustom field name for label and value and disabled{ label: string, value: string, disabled: string }{ label: 'label', value: 'value',disabled:'disabled' }
multipleWhether to allow multiple selectionsbooleanfalse
onChangeTriggered when the value is changed(value: SelectorValue[], extend: { items: SelectorOption[] }) => void-
optionsOptional selectorSelectorOption[]-
showCheckMarkWhether to show the check markbooleantrue
valueSelected valueSelectorValue[]-

CSS Variables

NameDescriptionDefault
--borderborder stylenone
--border-radiusBorder radius of options2px
--checked-borderBorder style when checkednone
--checked-colorBackground color when checkedvar(--adm-color-wathet)
--checked-text-colorText color when checkedvar(--adm-color-primary)
--colorBackground color#f5f5f5
--paddingPadding of options8px 16px
--text-colorText colorvar(--adm-color-text)
--gapThe gap between items, only take effect with columns8px
--gap-horizontalThe horizontal gap between items, only take effect with columnsvar(--gap)
--gap-verticalThe vertical gap between items, only take effect with columnsvar(--gap)

Types

SelectorValue

type SelectorValue = string | number

SelectorOption

NameDescriptionTypeDefault
descriptionDescription textReactNode-
disabledWhether disabledbooleanfalse
labelLabel textReactNode-
valueValue of the optionSelectorValue-

Generics

Selector supports generics, you can manually control the type of attributes such as value and onChange in the following way:

<Selector<'a' | 'b' | number>
  options={options}
  defaultValue={['a']}
  onChange={arr => console.log(arr)}
/>