跳到主要内容

Search

搜索框:input 的搜索语义壳(形状 + 搜索键 + 取消)。防抖触发(窗口内多次输入 合并为一次 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有值时显示清除按钮booleantrue
disabled禁用booleanfalse
readonly只读(可聚焦不可输入)booleanfalse
maxLength最大输入长度number—
cancelText取消按钮文案(不传 / 空串 = 不渲染)string—
ariaLabel无障碍名称(未传取 placeholder / 值兜底)string—
sxsx 快速布局属性LhSxProps—
prefix前缀区(plus #prefix;默认搜索图标 ⌕)ReactNode—

Events​

属性说明类型
onChange搜索词变化(防抖合并后回调;modelValue 回写路径)(value: string) => void
onSearch提交搜索(Enter 键 / 小程序搜索键)(value: string) => void
onCancel取消按钮点击() => void
onClear清除按钮点击(清除后回写空串)() => void
onFocus聚焦() => void
onBlur失焦(失焦前 flush 防抖待发值)() => void

Accessibility​

  • 根节点 aria-label 未传时按 ariaLabel > placeholder > 值 兜底;清除按钮 带独立 aria-label="清除"

Form differences across platforms​

  • plus / vue2: v-model 回写 + Enter 提交,prefix 为具名插槽
  • React: v-model 拆为 modelValue + onChange,prefix 为 ReactNode prop
  • uniapp / wxapp / alipay: 原生 input confirm-type="search" + bindconfirm 映射到 search 事件(见各端文档)