Search 搜索框
搜索框:input 的搜索语义壳(形状 + 搜索键 + 取消)。防抖触发(窗口内多次 输入合并为一次 update:modelValue)、类名与清除显隐全部消费 @lh-ui/share/core/search 纯逻辑;输入为原生 input (confirm-type="search",@confirm 映射到 search 事件)。
平台差异(登记):搜索键由原生 input 的
confirm-type="search"+@confirm承接(web 三端为 Enter 键);只读 / 禁用态清除按钮同样不显示 (纯函数派生一致)。
基础用法
vue
<template>
<lh-search
v-model="value"
placeholder="请输入关键词"
aria-label="搜索商品"
@search="onSearch"
@clear="onClear"
/>
<text>当前值:{{ value || '(空)' }}|已提交 {{ times }} 次</text>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const value = ref('')
const times = ref(0)
function onSearch(v: string) {
times.value += 1
}
function onClear() {
value.value = ''
}
</script>方角与取消按钮
vue
<lh-search v-model="value" shape="square" cancel-text="取消" @cancel="onCancel" />cancelText 传入非空串才渲染取消按钮(点击触发 cancel 事件)。
禁用与只读
vue
<lh-search model-value="固定词" disabled />
<lh-search model-value="只读词" readonly />Props
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| modelValue | 搜索词(受控,v-model) | string | '' |
| placeholder | 占位文案 | string | '' |
| shape | 形状 | "round" | "square" | 'round' |
| clearable | 有值时显示清除按钮 | boolean | true |
| disabled | 禁用 | boolean | false |
| readonly | 只读(可聚焦不可输入) | boolean | false |
| maxLength | 最大输入长度 | number | — |
| cancelText | 取消按钮文案(不传 / 空串 = 不渲染) | string | — |
| ariaLabel | 无障碍名称(未传取 placeholder / 值兜底) | string | — |
| customClass | 自定义类名(透传到根节点) | string | — |
| sx | sx 快速布局属性 | LhSxProps | — |
Events
| 事件 | 说明 | 载荷 |
|---|---|---|
| update:modelValue | 搜索词变化(防抖合并后回调;v-model 回写路径) | value: string |
| search | 提交搜索(原生 input confirm-type=search) | value: string |
| cancel | 取消按钮点击 | — |
| clear | 清除按钮点击(清除后回写空串) | — |
| focus | 聚焦 | — |
| blur | 失焦(失焦前 flush 防抖待发值) | — |
无障碍
根节点 aria-label 未传时按 ariaLabel > placeholder > 值 兜底;清除按钮 带独立 aria-label="清除"。

