Input 输入
接收单行或多行文本的输入框
用法
基础
Loading demo...
搜索行
Loading demo...
输入类型
type 可选 text、password、textarea、date、email、number;rows 设定文本域行数。
Loading demo...
只读与禁用
Loading demo...
可清空
clearable 在有值时显示可聚焦的清空按钮,禁用或只读时隐藏。
Loading demo...
前后缀
prefix / suffix 插槽优先于 prefixIcon / suffixIcon。
Loading demo...
最佳实践
- 焦点只用边缘(ring)与阴影的细微变化表达;除非外层表单有统一规范,不要在外层再加一圈 focus ring。
- 工具栏与列表筛选用轻量的搜索态;Enter 搜索与防抖远程搜索属于契约时,改用
TxSearchInput。 type="number"的值可能是 number 或'',持久化前先在 schema 中归一化。- 同一字段的图标只用插槽或图标 prop 其中一种。
边缘与状态
边缘是 1px 内描边,不改变尺寸与内容位置;焦点时加 3px 光晕,错误时描边变红,禁用时用禁用底色。
Loading demo...
API 参考
属性
| Property | Type | Default | Description |
|---|---|---|---|
| modelValue | 输入值,配合 v-model 使用。 | ||
| placeholder | 占位文本。 | ||
| type | 输入类型;textarea 渲染多行文本域。 | ||
| disabled | 禁用输入。 | ||
| readonly | 只读。 | ||
| clearable | 有值时显示清空按钮。 | ||
| rows | 文本域行数,仅 textarea 有效。 | ||
| prefixIcon | 前缀图标 class;prefix 插槽优先。 | ||
| suffixIcon | 后缀图标 class;suffix 插槽优先。 | ||
| capsLockText | 密码框大写锁定提示的文案,经 role="status" 播报。 |
事件
| Property | Type | Default | Description |
|---|---|---|---|
| update:modelValue | - | 值变化时触发。 | |
| input | - | 输入时触发,参数同 update:modelValue。 | |
| focus | - | 原生输入控件聚焦时触发。 | |
| blur | - | 原生输入控件失焦时触发。 | |
| clear | - | 清空后触发。 |
插槽
| Property | Type | Default | Description |
|---|---|---|---|
| prefix | - | - | 前缀内容,替代 prefixIcon。 |
| suffix | - | - | 后缀内容,替代 suffixIcon。 |
暴露方法
| Property | Type | Default | Description |
|---|---|---|---|
| focus | - | 聚焦原生输入控件。 | |
| blur | - | 让原生输入控件失焦。 | |
| clear | - | 清空;禁用或只读时无效。 | |
| setValue | - | 设置值并派发 update:modelValue 与 input。 | |
| getValue | - | 返回当前值。 | |
| inputEl | - | 原生 input 或 textarea 的引用。 |
概述
type="number"非空时派发Number(value),清空时为''。- 清空依次派发
update:modelValue、input、clear;禁用或只读时清空无效。 - 外层保留
class/style,其余 attrs 透传给原生input/textarea。 - 在
TxFormItem中自动取得 id、aria-describedby、aria-invalid与required,显示错误时边框变红;表单的disabled同样生效。显式传入的属性优先。
技术实现
index.ts同时导出TuffInput与TxInput。- 源码:
packages/tuffex/packages/components/src/input/。
查看源码
packages/tuffex/packages/components/src/input/index.ts