Search Search
Manage search keywords, clearing, cancellation and submission.
Import
Use <hui-search> with uni-app easycom. Import public types from @nscode/handy-uni. For ordinary Vue 3, install the preview plugin from @nscode/handy-uni/web and register its components.
Examples
Interact with the controls to see values and event results on the page.
vue
<template>
<view>
<hui-search
ref="control"
v-model="keyword"
placeholder="搜索名称 / Search names"
show-action="always"
clearable
@update:model-value="event0"
@input="event1"
@search="event2"
@change="event3"
@clear="event4"
@cancel="event5"
@focus="event6"
@blur="event7"
@click-input="event8"
/>
<text>{{ keyword }}</text
><hui-button @click="control?.focus()">聚焦 / Focus</hui-button>
<hui-button @click="() => control?.focus()">focus()</hui-button>
<hui-button @click="() => control?.blur()">blur()</hui-button>
<hui-button @click="() => control?.clear()">clear()</hui-button>
<text>{{ lastEvent }}</text>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('No event yet')
const describe = (value: unknown) => {
try {
return JSON.stringify(value) ?? String(value)
} catch {
return String(value)
}
}
const control = ref()
const keyword = ref('')
const event0 = (arg0: unknown) => {
lastEvent.value = 'update:modelValue' + ': ' + [describe(arg0)].join(', ')
}
const event1 = (arg0: unknown) => {
lastEvent.value = 'input' + ': ' + [describe(arg0)].join(', ')
}
const event2 = (arg0: unknown) => {
lastEvent.value = 'search' + ': ' + [describe(arg0)].join(', ')
}
const event3 = (arg0: unknown) => {
lastEvent.value = 'change' + ': ' + [describe(arg0)].join(', ')
}
const event4 = () => {
lastEvent.value = 'clear'
}
const event5 = () => {
lastEvent.value = 'cancel'
}
const event6 = (arg0: unknown) => {
lastEvent.value = 'focus' + ': ' + [describe(arg0)].join(', ')
}
const event7 = (arg0: unknown) => {
lastEvent.value = 'blur' + ': ' + [describe(arg0)].join(', ')
}
const event8 = (arg0: unknown) => {
lastEvent.value = 'click-input' + ': ' + [describe(arg0)].join(', ')
}
</script>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
modelValue | string | undefined | Controlled value; undefined means omitted. |
defaultValue | string | '' | Initial uncontrolled value; ignored in controlled mode. |
placeholder | string | — | Placeholder when no value is selected or entered. |
shape | "round" | "square" | 'round' | Selection indicator shape. |
showAction | "focus" | "always" | "never" | 'focus' | When to show search cancellation: never, focus or always. |
actionText | string | — | Search cancellation text. |
clearOnCancel | boolean | true | Clear the keyword when cancelling search. |
clearable | boolean | true | Show the clear action. |
disabled | boolean | false | Disable interaction. |
readonly | boolean | undefined | Read-only presentation without value changes. |
autofocus | boolean | false | Request focus after mounting, subject to platform restrictions. |
maxlength | number | — | Maximum input length. |
size | ComponentSize | — | Component size; inherits configuration when omitted. |
Root attributes: common props. A Boolean default of undefined supports inheritance; explicit false overrides it. Other Boolean props default to false unless listed otherwise.
Events
| Event | Parameters | Description |
|---|---|---|
update:modelValue | (value: string) | Request a controlled value update. |
input | (value: string) | Emitted with the normalized input value. |
search | (value: string) | Search keyword submitted. |
change | (value: string) | Emitted after the value changes. |
clear | () | Emitted after clearing. |
cancel | () | Cancellation action. |
focus | (event: unknown) | Input gained focus. |
blur | (event: unknown) | Input lost focus. |
click-input | (event: unknown) | Reports the corresponding interaction result. |
Slots
| Slot | Parameters | Description |
|---|---|---|
left | — | Custom left region; replaces its fallback content. |
prefix | — | Custom prefix region; replaces its fallback content. |
suffix | — | Custom suffix region; replaces its fallback content. |
action | — | Custom action region; replaces its fallback content. |
Methods
| Method | Signature | Description |
|---|---|---|
focus | (): void | Request input focus. |
blur | (): void | Request input blur. |
clear | (): void | Clear using the component input flow. |
Types
SearchProps、SearchExpose、SearchEmits are available from @nscode/handy-uni.
Platform notes
| Behavior | uni-app H5 | WeChat Mini Program | App-vue | Ordinary Vue 3 Web (preview) |
|---|---|---|---|---|
| Basic interaction | Supported; device checks pending | Supported; device checks pending | Supported; device checks pending | Supported by the web platform adapter |
Follow the smoke checklist. Device evidence is tracked separately; unit tests do not establish device acceptance.