跳到主要内容

输入框 Input

输入框用于通过键盘输入内容,适用于单行文本

安装使用​

import { TiInput } from '@titian-design/mobile-react'

用法示例​

基本用法
codesanbox
copy
code
键盘类型
当只需要弹起特定类型键盘,无需对输入内容格式化的情况推荐使用。
codesanbox
copy
code
左侧label文字缺省的行数
codesanbox
copy
code
错误提示
codesanbox
copy
code
输入类型
codesanbox
copy
code
输入对齐方式
codesanbox
copy
code
使用图标
codesanbox
copy
code
输入框左右使用插槽
+ 86
发验证码
codesanbox
copy
code
键盘确认按钮文字
codesanbox
copy
code

TiInput API​

属性 Properties​

名称类型必填默认值说明备注
typestring否textinput 的类型,可选值为 text number digit safe-password , 以及iniput 原生 type-
inputmodestring否text键盘类型,更多取值见input原生inputmode
valuestring否-当前输入的值-
passwordboolean否false是否是密码类型-
placeholderstring否-输入框为空时占位符-
disabledboolean否false是否禁用-
maxlengthnumber否140最大输入长度,设置为 -1 的时候不限制最大长度-
prefixIconstring否-左侧图标名称-
labelstring否-输入框左侧文本-
dividerboolean否true是否显示底部分割线-
requiredboolean否false是否显示必填星号-
clearableboolean否true是否启用清除控件-
readOnlyboolean否false是否只读-
textAlignstring否left输入框内容对齐方式,可选值为 left right-
errorboolean否false是否将输入内容标红-
errorMessagestring否-底部错误提示文案,为空时不展示-
autofocusboolean否false获取焦点-
confirmTypestring否done设置键盘右下角按钮的文字,仅在 type='text'时生效-
extStylestring | Record<string, string>否-根节点样式-
ellipsisLinenumber否0左侧文字缺省的行数-

事件 Events​

名称参数列表描述备注
onInput(e: CustomEvent<{value: number | string, keyCode: string}>) => void键盘输入时触发-
onFocus(e: CustomEvent<{value: number | string}>) => void输入框聚焦时触发-
onBlur(e: CustomEvent<{value: number | string}>) => void输入框失去焦点时触发-
onConfirm(e: CustomEvent<{value: number | string}>) => void点击完成按钮时触发-
onClear(e: CustomEvent) => void点击清除图标是触发-
onChange(e: CustomEvent<{value: number | string}>) => void输入值改变时触发-

插槽 Slots​

名称说明备注
prefixIconlabel 左侧图标-
prefix输入框左侧侧插槽-
suffix输入框右侧插槽-

外部样式类 External Classes​

名称说明备注
extClass根节点样式类-
labelClass输入框左侧文本样式类-
inputClassinput 样式类-

CSS 变量 CSS Variable​

变量默认值说明备注
--input-line-heighttheme.lineHeight.multiline.t6文字行高-
--input-padding-vtheme.spacing.vertical.v8垂直方向内边距-
--input-padding-htheme.spacing.horizontal.h7水平方向内边距-
--input-font-sizetheme.fontSize.t6字体大小-
--input-label-width168px左侧 label,包括间隙。输入框距最左侧宽度-
--input-title-max-width140px左侧文字局域最大宽度-
--input-placeholder-colortheme.color.gray.texticon.400placeholder 颜色-
--input-font-colortheme.color.gray.texticon.900输入文字颜色-
--input-placeholder-error-colortheme.color.function.error.1000错误提示下 placeholder 颜色-
--input-widthautoinput容器宽度-
--input-background#fffinput容器背景-
--input-required-font-sizetheme.fontSize.t4必填星号,字号-
--input-required-line-heighttheme.lineHeight.multiline.t5必填星号,行高-
--input-required-colortheme.color.function.error.1000必填星号,颜色-
--input-required-gaptheme.spacing.gap.g1必填星号,距离左侧文字gap-
--input-error-message-font-sizetheme.fontSize.t4错误信息的文字大小-