RegionPicker
One to four region levels over application-provided data. Administrative datasets are not bundled.
Import
With uni-app easycom, use hui-region-picker。 Standalone Vue imports @nscode/handy-uni/web HuiRegionPicker 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 value = ref(null)
const data = [
{
value: 'p',
label: '示例省 / Province',
children: [
{
value: 'c',
label: '示例市 / City',
children: [{ value: 'd', label: '示例区 / District' }]
}
]
}
]
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 = 'load-error' + ': ' + JSON.stringify([arg0])
}
function event4() {
result.value = 'clear' + ': ' + JSON.stringify([])
}
function event5(arg0: unknown) {
result.value = 'update:visible' + ': ' + JSON.stringify([arg0])
}
function event6() {
result.value = 'open' + ': ' + JSON.stringify([])
}
function event7() {
result.value = 'opened' + ': ' + JSON.stringify([])
}
function event8(arg0: unknown) {
result.value = 'close' + ': ' + JSON.stringify([arg0])
}
function event9() {
result.value = 'closed' + ': ' + JSON.stringify([])
}
</script>
<template>
<view>
<hui-region-picker
v-model="value"
:data="data"
:level="3"
mode="wheel"
clearable
@update:model-value="event0"
@change="event1"
@select="event2"
@load-error="event3"
@clear="event4"
@update:visible="event5"
@open="event6"
@opened="event7"
@close="event8"
@closed="event9"
></hui-region-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 { RegionPickerExpose } from '@nscode/handy-uni'
const control = ref<RegionPickerExpose>()
const value = ref<string[] | null>(['a'])
const data = [{ value: 'a', label: 'A', isLeaf: true }]
</script>
<template>
<view>
<hui-region-picker ref="control" v-model="value" :data="data" />
<hui-button @click="control?.clear()">Clear</hui-button>
<text>{{ value }}</text>
</view>
</template>
Props
| Property | Type | Default | Description |
|---|---|---|---|
model-value | CascadeKey[] | null | undefined | — | Controlled committed value; display remains unchanged until the parent writes back. |
default-value | CascadeKey[] | null | undefined | — | Initial uncontrolled value. |
props | CascaderFieldNames | undefined | — | Field mapping; omitted fields use standard label/value/children/disabled names. |
load | ((parent: CascadeOption | null, level: number) => Promise<CascadeOption[]>) | undefined | — | Load children from the current parent; failed requests can be retried and stale results are ignored. |
mode | "cascader" | "wheel" | undefined | — | Tabbed cascader lists or wheel columns. |
check-strictly | boolean | undefined | — | Disable linked checking; allow non-leaf selection in single tree or cascader selection. |
labels | string[] | undefined | — | Fallback labels while source records are unavailable, in model order. |
show-all-levels | boolean | undefined | — | Show the full path instead of its final label. |
display-format | ((selectedOptions: CascadeOption[]) => string) | undefined | — | Format trigger text from selected source records and paths. |
before-confirm | ((value: CascadeKey[] | null, context: CascaderChangeContext) => unknown) | undefined | — | Confirmation guard; false, thrown errors and rejected promises preserve the draft. |
level-titles | string[] | undefined | — | Placeholder title for each level. |
data | CascadeOption[] | undefined | — | Full tree records supplied by the application. |
level | RegionLevel | undefined | 3 | Region level count, one through four; leaf nodes may finish earlier. |
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 uses the first defined value from the prop, FormItem, Form and 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: CascadeKey[] | null) | Requests a controlled value update. |
change | (value: CascadeKey[] | null, context: CascaderChangeContext) | Reports change with the arguments shown in the example. |
select | (value: CascadeKey[], context: { selectedOptions: CascadeOption[]; level: number; }) | Reports select with the arguments shown in the example. |
load-error | (info: { level: number; error: unknown; }) | Reports load-error 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. |
Slots
| Slot | Description |
|---|---|
trigger | Trigger scope: {text,value,open}. |
title | Title content. |
option | Option content with the original option and selection state. |
empty | Empty-state content. |
Methods
| Method | Signature |
|---|---|
open | () => void |
close | () => void |
clear | () => void |
Types
RegionPickerProps、RegionPickerEmits、RegionPickerExpose。 Public types are exported from the package entry.
Platform notes
| Scope | Behavior and validation limits |
|---|---|
| Shared implementation | Adapts region fields and levels on Cascader. It does not request location or download region data. |
| Device checks pending | With business region data, check levels, initial values, clearing and missing children. Platform behavior follows Cascader. |
See examples/uni-demo/smoke/RegionPicker.md for the checklist. Unit tests do not replace device acceptance.