Search
A search box: a search-semantic shell over input (shape + search key + cancel). Debounced emitting (multiple inputs within the window are merged into a single update:modelValue), the search-key check (Enter / mini-program confirm-type) and the class name / clear-button visibility all consume the pure logic in @lh-ui/share/core/search; the clear button reuses the __clear visual treatment of input.
Basic Usage
Current value: , submitted 0 times (not submitted yet)
<script setup lang="ts">
import { ref } from 'vue'
import { LhSearch } from '@lh-ui/vue3'
const value = ref('')
const times = ref(0)
const last = ref('')
function onSearch(v: string) {
times.value += 1
last.value = `Submitted "${v}"`
}
function onClear() {
last.value = 'Cleared'
}
</script>
<template>
<LhSearch v-model="value" placeholder="Enter keywords" @search="onSearch" @clear="onClear" />
</template>Shape and cancel button
shape="square" gives square corners; a cancel button is only rendered when cancelText is a non-empty string (clicking it triggers the cancel event, often paired with blurring to collapse the keyboard on the business side).
<script setup lang="ts">
import { ref } from 'vue'
import { LhSearch } from '@lh-ui/vue3'
const value2 = ref('Lipstick')
const cancelTip = ref('')
function onCancel() {
cancelTip.value = 'Cancel clicked'
}
</script>Disabled and readonly
Disabled cannot be focused or interacted with; readonly is focusable but not editable (the clear button is not shown in either state).
<LhSearch model-value="Fixed term" disabled />
<LhSearch model-value="Read-only term" readonly />Props
| Prop | Description | Type | Default |
|---|---|---|---|
| modelValue | Search term (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 | Read-only (focusable but not editable) | boolean | false |
| maxLength | Max input length | number | — |
| cancelText | Cancel button text (not passed / empty string = not rendered) | string | — |
| ariaLabel | Accessible name (falls back to placeholder / value when not passed) | string | — |
| sx | sx quick-layout props | LhSxProps | — |
Events
| Event | Description | Payload |
|---|---|---|
| update:modelValue | Search term change (callback after debounce merging; the v-model write-back path) | value: string |
| search | Submit search (Enter key / mini-program search key) | value: string |
| cancel | Cancel button click | — |
| clear | Clear button click (writes back an empty string after clearing) | — |
| focus | Focus | — |
| blur | Blur (flushes any 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 in the order ariaLabel > placeholder > value; the clear button carries its own aria-label="Clear"; the input element itself does not re-declare a name.
Cross-platform differences
- The three web platforms: Enter to submit + debounced write-back; uniapp / wxapp / alipay map the native input's
confirm-type="search"+bindconfirmto thesearchevent - The readonly / disabled states also hide the clear button on the three mini-program platforms (consistent derivation from pure functions)

