Search
Search box: a search-semantic shell over input (shape + submit key + cancel).
The debounce trigger (multiple inputs within the window merge into one
onChange), submit-key detection (Enter / mini-program confirm-type=search),
class names and clear-button visibility are all pure logic consumed from
@lh-ui/share/core/search; the clear button reuses input's __clear visual.
Basic usage
Search (debounced write-back + Enter submit + clear / cancel)
Current value:(empty)|Submitted 0 times:Not submitted yet
import { useState } from 'react'
import { LhSearch } from '@lh-ui/react'
export default function Demo() {
const [value, setValue] = useState('')
return (
<LhSearch
modelValue={value}
onChange={setValue}
placeholder="Enter a keyword"
onSearch={(v) => console.log('submit', v)}
/>
)
}
Disabled and readonly
<LhSearch modelValue="fixed" disabled />
<LhSearch modelValue="readonly" readonly />
Search API
Props
| Name | Description | Type | Default |
|---|---|---|---|
| modelValue | Search keyword (controlled) | 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 rendered when empty) | string | — |
| ariaLabel | Accessible name (falls back to placeholder / value) | string | — |
| sx | Quick layout props | LhSxProps | — |
| prefix | Prefix area (plus #prefix; default search icon ⌕) | ReactNode | — |
Events
| Name | Description | Type |
|---|---|---|
| onChange | Keyword change (debounced; modelValue write-back path) | (value: string) => void |
| onSearch | Submit search (Enter / mini-program search key) | (value: string) => void |
| onCancel | Cancel button click | () => void |
| onClear | Clear button click (writes back empty string) | () => void |
| onFocus | Focus | () => void |
| onBlur | Blur (flushes pending debounced value) | () => void |
Accessibility
- The root
aria-labelfalls back throughariaLabel > placeholder > value; the clear button carries its ownaria-label="清除"
Differences across platforms
- plus / vue2: v-model write-back + Enter submit, prefix is a named slot
- React: v-model splits into
modelValue+onChange, prefix is a ReactNode prop - uniapp / wxapp / alipay: native input
confirm-type="search"+bindconfirmmapped to the search event (see each platform's docs)