SelectPicker
Preserves string, number and boolean values, with filtering, selection limits and draft confirmation.
Import
With uni-app easycom, use hui-select-picker。 Standalone Vue imports @nscode/handy-uni/web HuiSelectPicker or installs the preview plugin.
Examples
Interaction and event results
Interact with the control. The latest event and its full payload are shown below. Popup selectors commit only after confirmation; cancellation keeps the previous value.
<script setup lang="ts">
import { ref } from 'vue'
const result = ref('')
const options = [
{ value: false, label: '否 / No' },
{ value: 0, label: '零 / Zero' },
{ value: 'a', label: '甲 / A' }
]
const value = ref([])
function event0(arg0: unknown) {
result.value = 'update:modelValue' + ': ' + JSON.stringify([arg0])
}
function event1(arg0: unknown, arg1: unknown) {
result.value = 'change' + ': ' + JSON.stringify([arg0, arg1])
}
function event2(arg0: unknown, arg1: unknown) {
result.value = 'select' + ': ' + JSON.stringify([arg0, arg1])
}
function event3(arg0: unknown) {
result.value = 'search' + ': ' + JSON.stringify([arg0])
}
function event4(arg0: unknown) {
result.value = 'exceed' + ': ' + JSON.stringify([arg0])
}
function event5() {
result.value = 'clear' + ': ' + JSON.stringify([])
}
function event6(arg0: unknown) {
result.value = 'update:visible' + ': ' + JSON.stringify([arg0])
}
function event7() {
result.value = 'open' + ': ' + JSON.stringify([])
}
function event8() {
result.value = 'opened' + ': ' + JSON.stringify([])
}
function event9(arg0: unknown) {
result.value = 'close' + ': ' + JSON.stringify([arg0])
}
function event10() {
result.value = 'closed' + ': ' + JSON.stringify([])
}
function event11() {
result.value = 'reach-bottom' + ': ' + JSON.stringify([])
}
</script>
<template>
<view>
<hui-select-picker
v-model="value"
:options="options"
multiple
filterable
select-all
:min="1"
:max="2"
clearable
@update:model-value="event0"
@change="event1"
@select="event2"
@search="event3"
@exceed="event4"
@clear="event5"
@update:visible="event6"
@open="event7"
@opened="event8"
@close="event9"
@closed="event10"
@reach-bottom="event11"
></hui-select-picker>
<text aria-live="polite">{{ result }}</text>
</view>
</template>
Clear through a component ref
clearable controls the visible clear action; clear() can also be called independently. Disabled, readonly and confirmation-pending controls ignore it. Clearing resets the panel draft and emits update:modelValue, clear, then change. Controlled trigger text waits for the parent update.
<script setup lang="ts">
import { ref } from 'vue'
import type { SelectPickerExpose } from '@nscode/handy-uni'
const control = ref<SelectPickerExpose>()
const value = ref<string | null>('a')
const options = [{ value: 'a', label: 'A' }]
</script>
<template>
<view>
<hui-select-picker ref="control" v-model="value" :options="options" />
<hui-button @click="control?.clear()">Clear</hui-button>
<text>{{ value }}</text>
</view>
</template>
Props
| Property | Type | Default | Description |
|---|---|---|---|
model-value | SelectModelValue | undefined | undefined | Controlled committed value; display remains unchanged until the parent writes back. |
default-value | SelectModelValue | undefined | null | Initial uncontrolled value. |
options | SelectOption[] | undefined | [] | Candidate options or a hierarchical option tree. |
props | SelectFieldNames | undefined | — | Field mapping; omitted fields use standard label/value/children/disabled names. |
multiple | boolean | undefined | false | Allow multiple selections. |
min | number | undefined | — | Lower value bound, or minimum count for multiple selection. |
max | number | undefined | — | Upper bound, star count for Rate, or maximum multiple-selection count. |
select-all | boolean | undefined | false | Show select-all for multiple selection, limited to filtered results. |
filterable | boolean | undefined | false | Show a search input. |
filter-method | ((keyword: string, option: SelectOption) => boolean) | undefined | — | Custom filter; return true to keep an option. |
confirm-on-select | boolean | undefined | undefined | Single selection confirms immediately by default; multiple selection waits for confirmation. |
scroll-to-selected | boolean | undefined | true | Scroll the first selected option into view when opening. |
empty-text | string | undefined | — | Empty-state text, defaulting to localized common.noData. |
no-match-text | string | undefined | — | No-match text, falling back to emptyText and common.noData. |
labels | string[] | undefined | — | Fallback labels while source records are unavailable, in model order. |
loading | boolean | undefined | false | Controlled refresh or loading state. |
debounce | number | undefined | 300 | Search delay in milliseconds; keyboard submission searches immediately. |
display-format | ((options: SelectOption[]) => string) | undefined | — | Format trigger text from selected source records and paths. |
before-confirm | ((value: SelectModelValue, context: SelectChangeContext) => unknown) | undefined | — | Confirmation guard; false, thrown errors and rejected promises preserve the draft. |
visible | boolean | undefined | undefined | Controlled popup visibility. |
default-visible | boolean | undefined | false | Initial uncontrolled visibility. |
title | string | undefined | — | Popup title. |
confirm-text | string | undefined | — | Localized confirm-button text. |
cancel-text | string | undefined | — | Localized cancel-button text. |
placeholder | string | undefined | — | Placeholder for an empty value. |
trigger | boolean | undefined | true | Render the trigger; false leaves only the popup. |
separator | string | undefined | — | Separator between trigger labels. |
clearable | boolean | undefined | false | Show clear action and emit model/change updates. |
disabled | boolean | undefined | false | Disable user interaction, including inherited form state. |
readonly | boolean | undefined | undefined | Readonly; inherit form context when omitted. |
size | ComponentSize | undefined | — | Size priority: prop → FormItem → Form → ConfigProvider. |
close-on-click-overlay | boolean | undefined | true | Request closing on overlay click. |
z-index | number | undefined | — | Explicit layer index; otherwise assigned by the page layer stack. |
root-portal | boolean | undefined | false | Use platform root-portal support on uni. |
safe-area-inset-bottom | boolean | undefined | true | Add bottom safe-area spacing. |
custom-class | string | undefined | '' | Additional root classes. |
custom-style | string | CSSProperties | undefined | — | Additional root styles. |
Events
| Event | Parameters | Description |
|---|---|---|
update:modelValue | (value: SelectModelValue) | Requests a controlled value update. |
change | (value: SelectModelValue, context: SelectChangeContext) | Reports change with the arguments shown in the example. |
select | (value: SelectModelValue, context: { option: SelectOption; checked: boolean; }) | Reports select with the arguments shown in the example. |
search | (keyword: string) | Reports search with the arguments shown in the example. |
exceed | (info: { reason: "min" | "max"; }) | Reports exceed with the arguments shown in the example. |
clear | () | Reports clear with the arguments shown in the example. |
update:visible | (visible: boolean) | Requests a controlled value update. |
open | () | Reports open with the arguments shown in the example. |
opened | () | Reports opened with the arguments shown in the example. |
close | (reason: string) | Reports close with the arguments shown in the example. |
closed | () | Reports closed with the arguments shown in the example. |
reach-bottom | () | Reports reach-bottom with the arguments shown in the example. |
Slots
| Slot | Description |
|---|---|
trigger | Trigger scope: {text,value,open}. |
title | Title content. |
selected | Selected area; {options,remove} in RemoteSelect, {value,remove} in SelectPicker. |
empty | Empty-state content. |
option | Option content with the original option and selection state. |
list-bottom | List footer content. |
footer | Confirmation and cancellation area. |
Methods
| Method | Signature |
|---|---|
open | () => void |
close | () => void |
setKeyword | (value: string) => void |
clear | () => void |
Types
SelectPickerProps、SelectPickerEmits、SelectPickerExpose。 Public types are exported from the package entry.
Platform notes
| Scope | Behavior and validation limits |
|---|---|
| Shared implementation | Options, filtering, single/multiple selection and draft confirmation are shared. Lists use the platform scroll container. |
| Device checks pending | Check long lists, search keyboards, confirm/cancel, select-all and selected-item scrolling; also check App popup/keyboard stacking. |
See examples/uni-demo/smoke/SelectPicker.md for the checklist. Unit tests do not replace device acceptance.