TuSearchBar 搜索栏
输入 + 清空 + 可选取消按钮,input / change / search / clear / cancel / focus / blur 事件。
搜索栏:输入框 + 清空按钮 + 可选取消按钮。完全受控:value 由父级维护,输入事件双端归一化(Web e.target.value / 小程序 e.detail.value)。
属性
| 名称 | 类型 | 说明 |
|---|---|---|
value | string | 输入值(受控),默认空串。 |
placeholder | string | 占位文案。 |
disabled | boolean | 禁用。 |
maxlength | number | 最大长度。 |
shape | round | square | 输入框形状,默认 round。 |
showCancel | boolean | 是否显示取消按钮,默认 false。 |
cancelText | string | 取消按钮文案,默认「取消」。 |
clearable | boolean | 非空时显示清空按钮,默认 true。 |
background | string | 背景色,默认浅灰。 |
事件:input / change(回传字符串值)、search(键盘确认键)、clear(点击清空,同时触发 input 空串)、cancel(点击取消)、focus / blur。
最近搜索:尚未搜索 —— 输入实时回传 input,回车触发 search(小程序 confirm-type=search)。
实例
ts
createComponent({
component: TuSearchBar,
props: { value: this.state.keyword, showCancel: true },
emitters: {
input: (v: string) => (this.state.keyword = v),
search: () => this.doSearch(this.state.keyword),
cancel: () => (this.state.keyword = ''),
},
})