RemoteSelect
Queries and pages through usePaging. Selected options are cached independently and labels never trigger a request.
Import
With uni-app easycom, use hui-remote-select。 Standalone Vue imports @nscode/handy-uni/web HuiRemoteSelect 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'
import type { RemoteSelectQueryParams } from '@nscode/handy-uni'
const result = ref('')
const value = ref([])
const query = async ({ keyword, page, pageSize }: RemoteSelectQueryParams) => ({
list: Array.from({ length: pageSize }, (_, i) => ({
value: (page - 1) * pageSize + i,
label: keyword + ' ' + ((page - 1) * pageSize + i)
})),
hasMore: page < 3
})
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(arg0: unknown) {
result.value = 'load-error' + ': ' + JSON.stringify([arg0])
}
function event6() {
result.value = 'clear' + ': ' + JSON.stringify([])
}
function event7(arg0: unknown) {
result.value = 'update:visible' + ': ' + JSON.stringify([arg0])
}
function event8() {
result.value = 'open' + ': ' + JSON.stringify([])
}
function event9() {
result.value = 'opened' + ': ' + JSON.stringify([])
}
function event10(arg0: unknown) {
result.value = 'close' + ': ' + JSON.stringify([arg0])
}
function event11() {
result.value = 'closed' + ': ' + JSON.stringify([])
}
</script>
<template>
<view>
<hui-remote-select
v-model="value"
:query="query"
multiple
:page-size="10"
:min-keyword-length="1"
@update:model-value="event0"
@change="event1"
@select="event2"
@search="event3"
@exceed="event4"
@load-error="event5"
@clear="event6"
@update:visible="event7"
@open="event8"
@opened="event9"
@close="event10"
@closed="event11"
></hui-remote-select>
<text aria-live="polite">{{ result }}</text>
</view>
</template>
Behavior and platform support
query receives { keyword, page, pageSize } and { signal }. Map business response shapes explicitly with normalize; data/rows fields are never guessed. Search trims whitespace, cancels requests and hides results below the minimum length. Use selectedOptions for selected records that have not been queried.
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 { RemoteSelectExpose } from '@nscode/handy-uni'
const control = ref<RemoteSelectExpose>()
const value = ref<string | null>('a')
const selectedOptions = [{ value: 'a', label: 'A' }]
</script>
<template>
<view>
<hui-remote-select
ref="control"
v-model="value"
:selected-options="selectedOptions"
:load-on-open="false"
/>
<hui-button @click="control?.clear()">Clear</hui-button>
<text>{{ value }}</text>
</view>
</template>
Props
| Property | Type | Default | Description |
|---|---|---|---|
model-value | SelectModelValue | undefined | — | Controlled committed value; display remains unchanged until the parent writes back. |
default-value | SelectModelValue | undefined | — | Initial uncontrolled value. |
props | SelectFieldNames | undefined | — | Field mapping; omitted fields use standard label/value/children/disabled names. |
multiple | boolean | undefined | — | 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 | — | Show select-all for multiple selection, limited to filtered results. |
confirm-on-select | boolean | undefined | — | Single selection confirms immediately by default; multiple selection waits for confirmation. |
scroll-to-selected | boolean | undefined | — | 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. |
debounce | number | undefined | — | 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. |
query | UniQuery<RemoteSelectQueryParams, unknown> | undefined | — | Query receives {keyword,page,pageSize} and {signal}. |
normalize | UniPageNormalizer<SelectOption> | undefined | — | Explicitly map a response to {list,total?,hasMore?}. |
page-size | number | undefined | 20 | Page size. |
selected-options | SelectOption[] | undefined | — | Selected records used for cached cross-page labels without a request. |
min-keyword-length | number | undefined | 0 | Cancel queries and hide results below this keyword length. |
load-on-open | boolean | undefined | true | Query on opening. |
keep-results | boolean | undefined | true | Preserve keyword and results. If false, reopening clears the keyword, reloads and invalidates old requests. |
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: SelectModelValue) | Requests a controlled value update. |
change | (value: SelectModelValue, context: { selectedOptions: SelectOption[]; }) | 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. |
load-error | (info: { scope: "refresh" | "first" | "more"; 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. |
selected | Selected area; {options,remove} in RemoteSelect, {value,remove} in SelectPicker. |
empty | Empty-state content. |
footer | Confirmation and cancellation area. |
Methods
| Method | Signature |
|---|---|
open | () => void |
close | () => void |
reload | () => Promise<boolean> |
clear | () => void |
Types
RemoteSelectProps、RemoteSelectEmits、RemoteSelectExpose。 Public types are exported from the package entry.
Platform notes
| Scope | Behavior and validation limits |
|---|---|
| Shared implementation | Remote requests use the business query adapter. Debouncing, cancellation and stale-request isolation are shared. |
| Device checks pending | Check search changes, loading more, retries and cancellation against real network requests; keep platform objects out of option data. |
See examples/uni-demo/smoke/RemoteSelect.md for the checklist. Unit tests do not replace device acceptance.