Skip to content

SelectPicker

Used for single or multiple selection from a set of options, usually combined with external cells or buttons to control popup display.

Component Types

Basic Usage

The default type is checkbox, and the value type of v-model is an array. Usually combined with v-model:visible to control popup visibility.

html
<wd-cell title="Select Address" :value="getDisplayValue(value)" is-link @click="show = true" />
<wd-select-picker v-model="value" v-model:visible="show" :columns="columns" @confirm="handleConfirm" />
ts
const columns = ref([
  { value: '101', label: 'Men\'s Clothing' },
  { value: '102', label: 'Luxury' },
  { value: '103', label: 'Women\'s Clothing' }
])

const value = ref<string[]>(['101'])
const show = ref(false)

function handleConfirm({ value }: { value: string[] }) {
  console.log(value)
}

Type Switching

Set type="radio" to enable single selection mode. In this case, the value type of v-model is string, number, or boolean.

html
<wd-select-picker type="radio" v-model="value" v-model:visible="show" :columns="columns" />

Component States

Disabled Options

Option data supports the disabled field to disable a specific item.

html
<wd-select-picker v-model="value" v-model:visible="show" :columns="columns" />
ts
const columns = ref([
  { value: '101', label: 'Men\'s Clothing', disabled: true },
  { value: '102', label: 'Luxury' },
  { value: '103', label: 'Women\'s Clothing' }
])

Loading

Set loading to display a loading state in the content area.

html
<wd-select-picker loading v-model="value" v-model:visible="show" :columns="columns" />

Component Styles

Setting Title

Customize the popup title through title.

html
<wd-select-picker v-model="value" v-model:visible="show" title="Multiple Selection" :columns="columns" />

Searchable

Set filterable to enable local search; both single and multiple selection modes are supported.

html
<wd-select-picker filterable v-model="value" v-model:visible="show" :columns="columns" />
<wd-select-picker filterable type="radio" v-model="singleValue" v-model:visible="show" :columns="columns" />

Special Styles

Option Change Event

When options inside the selector change, the change event is triggered.

html
<wd-select-picker v-model="value" v-model:visible="show" :columns="columns" @change="handleChange" />
ts
function handleChange({ value }: { value: string[] }) {
  console.log(value)
}

Pre-confirmation Validation

Set before-confirm to perform synchronous or asynchronous validation before clicking the confirm button. Returns false or Promise<false> to prevent closing the popup.

html
<wd-select-picker v-model="value" v-model:visible="show" :columns="columns" :before-confirm="beforeConfirm" />
ts
const beforeConfirm = (value: string[]) => {
  return new Promise<boolean>((resolve) => {
    if (value.length > 0) {
      resolve(false)
    } else {
      resolve(true)
    }
  })
}

Auto-complete

In radio mode, you can hide the confirm button with show-confirm="false" to automatically complete after selection.

html
<wd-select-picker type="radio" :show-confirm="false" v-model="value" v-model:visible="show" :columns="columns" />

Attributes

ParameterDescriptionTypeDefault Value
v-modelSelected item, array when checkbox, string, number, or boolean when radiostring | number | boolean | (string | number | boolean)[]-
visible / v-model:visibleControls popup display statebooleanfalse
titlePopup titlestring'Selector'
checked-colorRadio or checkbox selected colorstring-
minMinimum number of selections, only effective for checkboxnumber0
maxMaximum number of selections, 0 means unlimited, only effective for checkboxnumber0
select-sizeSelector internal option sizestring-
loadingWhether to show loading statebooleanfalse
loading-colorLoading icon colorstring'#4D80F0'
close-on-click-modalWhether to close when clicking the maskbooleantrue
columnsSelector data, one-dimensional arrayRecord<string, any>[][]
typeSelector type, optional values are checkbox, radiostring'checkbox'
value-keyThe key for the value field in option objectsstring'value'
label-keyThe key for the display text field in option objectsstring'label'
confirm-button-textConfirm button textstring'Confirm'
before-confirmPre-confirmation validation function, receives current selected value, returns boolean or Promise<boolean>function-
z-indexPopup z-indexnumber15
safe-area-inset-bottomWhether to adapt to bottom safe areabooleantrue
filterableWhether to support local searchbooleanfalse
filter-placeholderSearch box placeholderstring'Search'
scroll-into-view v0.1.34Whether to scroll to selected item when reopenedbooleantrue
custom-content-classCustom popup content area class namestring''
show-confirm v1.2.8Whether to show confirm button, only effective in radio modebooleantrue
root-portal v1.11.0Whether to detach from page structure, used to solve fixed positioning issuesbooleanfalse
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

Option Data Structure

ParameterDescriptionTypeDefault Value
valueOption valuestring | number | boolean-
labelOption textstring-
disabledWhether to disable this optionbooleanfalse

Events

Event NameDescriptionParameters
changeTriggered when options inside the selector change{ value }
cancelTriggered when clicking close button or mask to close-
confirmTriggered when clicking confirm{ value, selectedItems }
openTriggered when popup opens-
close v1.2.29Triggered when popup closes-

Methods

Method NameDescriptionType
openOpen popup() => void
closeClose popup() => void

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-select-picker-bg$filled-oppo选择器背景色
--wot-select-picker-loading-opacity$opacity-disabledloading 状态下透明度
--wot-select-picker-loading-icon-size$n-48loading 图标尺寸
--wot-select-picker-wrapper-padding-horizontal$padding-main内容区水平内边距
--wot-select-picker-wrapper-max-height$n-375内容区最大高度
--wot-select-picker-text-active-color$primary-6选中态文字颜色
--wot-select-picker-footer-padding$padding-tight $padding-loose底部内边距
--wot-select-picker-footer-border-color$border-light确认区域上边框颜色

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.