Search
検索ボックス:input の検索セマティクスシェル(形状 + 送信キー + キャンセル)。
デバウンストリガ(ウィンドウ内の複数入力を1回の onChange に統合)、送信キー
判定(Enter / ミニプログラムの confirm-type=search)、クラス名とクリアボタンの
表示はすべて @lh-ui/share/core/search の純粋ロジックを消費します;クリア
ボタンは input の __clear 見た目を再利用します。
基本的な使い方
検索(デバウンス書き戻し + Enter 送信 + クリア / キャンセル)
現在値:(空)|送信 0 回:未送信
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="キーワードを入力"
onSearch={(v) => console.log('送信', v)}
/>
)
}
無効と読み取り専用
<LhSearch modelValue="固定" disabled />
<LhSearch modelValue="読み取り専用" readonly />
Search API
Props
| 名前 | 説明 | 型 | デフォルト |
|---|---|---|---|
| modelValue | 検索キーワード(制御) | string | '' |
| placeholder | プレースホルダーテキスト | string | '' |
| shape | 形状 | "round" | "square" | 'round' |
| clearable | 値があるときクリアボタンを表示 | boolean | true |
| disabled | 無効 | boolean | false |
| readonly | 読み取り専用(フォーカス可能だが編集不可) | boolean | false |
| maxLength | 最大入力長 | number | — |
| cancelText | キャンセルボタンのテキスト(空なら非表示) | string | — |
| ariaLabel | アクセシブル名(placeholder / 値にフォールバック) | string | — |
| sx | クイックレイアウト props | LhSxProps | — |
| prefix | プレフィックス領域(plus #prefix;デフォルトは検索アイコン ⌕) | ReactNode | — |
Events
| 名前 | 説明 | 型 |
|---|---|---|
| onChange | キーワード変化(デバウンス;modelValue 書き戻しパス) | (value: string) => void |
| onSearch | 検索送信(Enter / ミニプログラムの検索キー) | (value: string) => void |
| onCancel | キャンセルボタンクリック | () => void |
| onClear | クリアボタンクリック(空文字を書き戻す) | () => void |
| onFocus | フォーカス | () => void |
| onBlur | ブラー(保留中のデバウ ンス値をフラッシュ) | () => void |
Accessibility
- ルートの
aria-labelはariaLabel > placeholder > 値の順でフォールバック; クリアボタンは専用のaria-label="清除"を持ちます
プラットフォーム間の差異
- plus / vue2: v-model 書き戻し + Enter 送信、prefix は名前付きスロット
- React: v-model は
modelValue+onChangeに分割、prefix は ReactNode prop - uniapp / wxapp / alipay: ネイティブ input の
confirm-type="search"+bindconfirmを search イベントにマッピング(各プラットフォームのドキュメントを参照)