Input 输入框
注:
- 支持表单,具体可参考 Form。
import { TaInput, TaCell, TaGroup, showToast } from '@/index'
export default function ExpInput() {
function onInput(value: string) {
showToast(`当前值为:${value}`)
}
return (
<>
<TaGroup title="基础用法">
<TaInput type="text" focus placeholder="请输入文本" />
<TaInput type="text" value="禁用" disabled />
<TaInput type="text" placeholder="showLimit=true" showLimit showClear />
</TaGroup>
<TaGroup title="textarea">
<TaInput
type="textarea"
placeholder="showLimit=true"
showLimit
maxlength={200}
/>
</TaGroup>
<TaGroup title="Slot prepend/append">
<TaInput
type="text"
focus
placeholder="请输入网址"
renderPrepend={() => 'https://'}
/>
<TaInput
type="text"
focus
placeholder="请输入网址"
renderAppend={() => '.com'}
/>
</TaGroup>
<TaGroup title="与 Cell 组合">
<TaCell label="文本">
<TaInput type="text" placeholder="请输入文本" />
</TaCell>
</TaGroup>
<TaGroup title="设置 type 类型">
<TaCell label="文本 text">
<TaInput type="text" placeholder="请输入文本" />
</TaCell>
<TaCell label="电话 tel">
<TaInput type="tel" placeholder="请输入电话" />
</TaCell>
<TaCell label="整数 digit">
<TaInput type="digit" placeholder="请输入整数" />
</TaCell>
<TaCell label="数字 number">
<TaInput type="number" placeholder="请输入数字" />
</TaCell>
<TaCell label="搜索 search">
<TaInput type="search" placeholder="请输入要搜索的内容" />
</TaCell>
<TaCell label="密码 password">
<TaInput type="password" placeholder="请输入密码" />
</TaCell>
<TaCell label="文本 textarea">
<TaInput type="textarea" placeholder="请输入多行文本" />
</TaCell>
</TaGroup>
<TaGroup title="其他">
<TaCell label="只读 readonly">
<TaInput type="text" value="只读文本" readonly />
</TaCell>
<TaCell label="禁用 disabled">
<TaInput type="text" value="禁用文本" disabled />
</TaCell>
<TaCell label="可清除 showClear">
<TaInput
type="text"
placeholder="请输入文本"
value="文本内容"
showClear
/>
</TaCell>
</TaGroup>
<TaGroup title="事件监听">
<TaCell label="input">
<TaInput
type="text"
placeholder="请输入文本"
showClear
onInput={onInput}
/>
</TaCell>
<TaCell label="change">
<TaInput
type="text"
placeholder="请输入文本"
showClear
onChange={onInput}
/>
</TaCell>
</TaGroup>
</>
)
}
Import
import { TaInput } from 'tantalum-ui-mobile-react'
具体的引入方式可以参考引入组件。
Props
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
value | string | number | '' | 否 | |
name | string | 否 | 标识 | |
type | string | 'text' | 否 | 类型 |
placeholder | string | 否 | 输入框为空时占位符 | |
disabled | boolean | false | 否 | 是否禁用 |
readonly | boolean | false | 否 | 是否只读 |
maxlength | string | number | 140 | 否 | 最大长度 |
focus | boolean | false | 否 | 是否获取焦点 |
showClear | boolean | false | 否 | 是否展示清除图标 |
type 的合法值
值 | 说明 |
---|---|
text | 文本 |
digit | 整数 |
number | 数字 |
password | 密码 |
search | 搜索 |
password | 密码 |
Events
事件 | 描述 | 回调函数参数 |
---|---|---|
onInput | 输入值改变时触发 | value: string |
onChange | 输入值改变且失焦后触发,含点击清空按钮 | value: string |
onFocus | 获取焦点时触发 | e: FocusEvent |
onBlur | 移出焦点时触发 | e: FocusEvent |
Slots
前置元素(renderPrepend)
<TaInput
type="text"
focus
placeholder="请输入网址"
renderPrepend={() => 'https://'}
/>
注:也可以传入 Icon
,比如常见的搜索。
后置元素(renderAppend)
<TaInput
type="text"
focus
placeholder="请输入网址"
renderAppend={() => '.com'}
/>