# Search
A search input: the search-semantic shell of an input (shape + search key + cancel). Debounced triggering (multiple inputs within the window are merged into a single update:modelValue), search-key detection (Enter / the mini-program confirm-type), class names, and the clear-button visibility all consume the pure logic of @lh-ui/share/core/search.
Search box (debounced write-back + Enter submit + cancel)
<template>
<div class="demo-col" style="gap: 18px">
<LhSearch v-model="value" placeholder="Type a keyword" @search="onSearch" @clear="onClear"></LhSearch>
<LhSearch v-model="value2" shape="square" cancel-text="Cancel" @cancel="onCancel"></LhSearch>
<p class="demo-note">
Current value: {{ value || value2 ? value + ' / ' + value2 : '(empty)' }} · submitted {{ times }} times: {{ last || 'not yet' }}
</p>
</div>
</template>
<script>
export default {
data: () => ({
value: '',
value2: 'Lipstick',
times: 0,
last: '',
}),
methods: {
onSearch(v) {
this.times += 1
this.last = 'Submitted "' + v + '"'
},
onClear() {
this.last = 'Cleared'
},
onCancel() {
this.last = 'Cancel clicked'
},
},
}
</script>
# Disabled and readonly
Disabled is not interactive; readonly is focusable but not editable (the clear button is hidden in both states).
<LhSearch model-value="Fixed word" disabled />
<LhSearch model-value="Readonly word" readonly />
# Props
| Prop | Description | Type | Default |
|---|---|---|---|
| modelValue | Search keyword (controlled, v-model) | string | '' |
| placeholder | Placeholder text | string | '' |
| shape | Shape | "round" \| "square" | 'round' |
| clearable | Show the clear button when there is a value | boolean | true |
| disabled | Disabled | boolean | false |
| readonly | Readonly (focusable but not editable) | boolean | false |
| maxLength | Max input length | number | — |
| cancelText | Cancel button text (not passed / empty string = not rendered) | string | — |
| ariaLabel | Accessibility name (falls back to placeholder / value when not passed) | string | — |
| sx | sx shorthand layout props | LhSxProps | — |
# Events
| Event | Description | Payload |
|---|---|---|
| update:modelValue | Keyword change (callback after debounce merging; the v-model write-back path) | value: string |
| search | Submit a search (Enter key / the mini-program search key) | value: string |
| cancel | Cancel button click | — |
| clear | Clear button click (writes an empty string back after clearing) | — |
| focus | Focus | — |
| blur | Blur (flushes the pending debounced value before blurring) | — |
# Slots
| Slot | Description |
|---|---|
| prefix | Prefix area (the search icon ⌕ by default) |
# Accessibility
When the root node's aria-label is not passed, it falls back by ariaLabel > placeholder > value; the clear button carries its own aria-label="Clear".
# Cross-target differences
- The three web targets: Enter to submit + debounced write-back; uniapp / wxapp / alipay map the native input's
confirm-type="search"+bindconfirmto thesearchevent - The three mini-program targets likewise hide the clear button in the readonly / disabled states (derived identically by pure functions)
← List PullRefresh →
Copyright © 2024-2026 FengMo WenXue