Skip to main content

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​

NameDescriptionTypeDefault
modelValueSearch keyword (controlled)string''
placeholderPlaceholder textstring''
shapeShape"round" | "square"'round'
clearableShow the clear button when there is a valuebooleantrue
disabledDisabledbooleanfalse
readonlyReadonly (focusable but not editable)booleanfalse
maxLengthMax input lengthnumber—
cancelTextCancel button text (not rendered when empty)string—
ariaLabelAccessible name (falls back to placeholder / value)string—
sxQuick layout propsLhSxProps—
prefixPrefix area (plus #prefix; default search icon ⌕)ReactNode—

Events​

NameDescriptionType
onChangeKeyword change (debounced; modelValue write-back path)(value: string) => void
onSearchSubmit search (Enter / mini-program search key)(value: string) => void
onCancelCancel button click() => void
onClearClear button click (writes back empty string)() => void
onFocusFocus() => void
onBlurBlur (flushes pending debounced value)() => void

Accessibility​

  • The root aria-label falls back through ariaLabel > placeholder > value; the clear button carries its own aria-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" + bindconfirm mapped to the search event (see each platform's docs)