For AI agents: the complete documentation index is available at https://rickyshin93.github.io/tao-ui/zh/llms.txt, the full documentation bundle is available at https://rickyshin93.github.io/tao-ui/zh/llms-full.txt, and this page is available as Markdown at https://rickyshin93.github.io/tao-ui/zh/components/input.md.
v0.0.57
  • 简体中文
  • Input

    数据录入@rockshin/tao-ui

    输入家族包含 Input、Input.Password、Input.Search、Input.TextArea 和 Input.OTP。

    何时使用

    用户需要输入短文本、搜索词或密码等单行内容时使用 Input。

    推荐

    • 提供可见标签或通过 FormField 关联标签。
    • 错误状态搭配具体错误信息。

    避免

    • 多行内容不要使用 Input,应使用 Textarea。

    代码演示

    基础用法

    TSX

    变体

    TSX

    尺寸与前后缀

    USD
    TSX

    三种尺寸

    为表单、紧凑工具栏和宽松布局选择尺寸。

    TSX

    清空与计数

    清空会触发 onChange 与 onClear,受控值由业务状态决定。

    6 / 24
    tao-ui
    TSX

    前后缀

    前后缀显示单位或上下文,输入值仅保存用户内容。

    https://.com
    $USD
    TSX

    密码输入框

    内置显示/隐藏按钮支持键盘、禁用态与受控 visibilityToggle。

    TSX

    搜索输入框

    按钮、回车与清空触发 onSearch;source 区分 input / clear。中文输入法确认时不搜索,loading 期间不重复触发。

    No search yet
    TSX

    原生约束与只读

    原生 email、required、maxLength 与 readOnly 可直接使用;错误状态由业务决定。

    TSX

    光标定位

    ref 继续指向原生输入框,InputRef 另外声明 input、nativeElement 与扩展 focus 选项。

    TSX

    自定义计数

    count.max 默认只标记超限;通过 strategy 与 exceedFormatter 按 Unicode 码点计数和截断。原生 maxLength 按 UTF-16 计数,两者分别配置。

    14 / 5
    2 / 5
    TSX

    多行输入

    Input.TextArea 与独立 Textarea 是同一组件,支持自动高度、清空、计数和回车事件。

    0 / 120
    TSX

    验证码

    输入自动前进,支持整串粘贴、左右方向键、退格、格式化与掩码。onInput 返回包含空位的数组,onChange 仅在填满时触发。

    -
    Enter all characters
    TSX

    前后附加内容

    addonBefore / addonAfter 显示附加标签;prefix / suffix 位于输入区域内。

    https://.com
    TSX

    API

    Input / Input.TextArea

    其余属性透传到原生 input / textarea。Input.TextArea 不支持 prefix、suffix 或 addon;独立 Textarea 用法保持兼容。

    PropTypeDefault
    value / defaultValueNative input value / textarea value—
    onChange(event) => void—
    allowClearboolean or { clearIcon?, disabled?, tabIndex? }false
    onClear() => void—
    showCountboolean or { formatter: ({ value, count, maxLength }) => ReactNode }false
    count{ max?, strategy?: (value) => number, show?: boolean or formatter, exceedFormatter?: (value, { max }) => string }—
    onPressEnter(event: KeyboardEvent) => void—
    size'small', 'medium', 'large'TaoProvider
    variant'outlined', 'filled', 'borderless', 'underlined'TaoProvider
    status / error'error' or 'warning' / boolean—
    disabled / readOnlybooleanTaoProvider / false
    prefix / suffixReactNode (Input only)—
    addonBefore / addonAfterReactNode (Input only)—
    autoSizeboolean or { minRows?, maxRows? } (TextArea only)false
    classNames / stylesSemantic part map or ({ props }) => map—

    计数超限不会自动截断;设置 count.exceedFormatter 才截断,中文输入法组合结束后执行。count.show 优先于 showCount。Input Semantic DOM:root / input / prefix / suffix / clear / count / addonBefore / addonAfter;TextArea:root / textarea / clear / count。

    Input.Password

    继承 Input 属性。

    PropTypeDefault
    visibilityToggleboolean or { visible?, onVisibleChange?, tabIndex? }true
    iconRender(visible: boolean) => ReactNodeEye icon

    Input.Search

    继承 Input 属性。搜索按钮默认不提交外层表单;onSearch 的 source 为 input 或 clear。

    PropTypeDefault
    enterButtonReactNode (boolean, label, native button or Button)false
    searchIconReactNodeSearch icon
    loadingbooleanfalse
    onSearch(value, event?, info?: { source: 'input' or 'clear' }) => void—
    classNames / stylesInput parts plus button—

    Input.OTP

    PropTypeDefault
    lengthPositive integer6
    value / defaultValuestring—
    formatter(value: string) => string—
    onInput(value: string[]) => void—
    onChange(value: string) => void (complete values)—
    maskboolean or stringfalse
    separatorReactNode or (index: number) => ReactNode—
    type / inputMode / autoCompleteNative input attributestext / — / —
    autoFocus / disabledbooleanfalse / TaoProvider
    size / variant / statusSame as InputTaoProvider / TaoProvider / —
    classNames / stylesroot / input / separator map or ({ props }) => map—

    Ref

    Input、Password、Search 的 ref 保留原生 HTMLInputElement,TextArea 保留 HTMLTextAreaElement。使用导出的 InputRef / TextAreaRef 类型可访问 focus({ preventScroll, cursor: 'start' | 'end' | 'all' })、blur()、nativeElement 及 input / textArea。不支持选区的原生输入类型仅聚焦。OTP 使用 OTPRef:focus()、blur()、nativeElement。

    API 参考本地 Ant Design 6.7.0,保留 tao-ui 的原生 ref、主题与 Semantic DOM 契约;不承诺直接替换 antd。bordered、prefixCls、antd 全局组件配置不在支持范围。underlined 当前通过 Input 家族的本地 variant 设置。