跳到主要内容

Input

Input 用于文本输入。支持 3 种 size、prefix/suffix/addon 插槽、clearable、error/warning 状态。


基础用法​

<Input native={{ placeholder: '请输入内容' }} />
<Input appearance={{ size: 'sm' }} native={{ placeholder: 'Small' }} />
<Input appearance={{ size: 'lg' }} native={{ placeholder: 'Large' }} />

状态​

<Input state={{ error: true }} native={{ placeholder: '错误状态' }} />
<Input state={{ warning: true }} native={{ placeholder: '警告状态' }} />
<Input state={{ disabled: true }} native={{ placeholder: '禁用' }} />

Prefix / Suffix​

💰kg
<Input content={{ prefix: '💰' }} native={{ placeholder: '金额' }} />
<Input content={{ suffix: 'kg' }} native={{ placeholder: '重量' }} />

Addon(前后缀块)​

http://.com
<Input
content={{ addonBefore: 'http://', addonAfter: '.com' }}
native={{ placeholder: 'example' }}
/>

Props 参考​

state — 运行时状态​

Prop类型默认值说明
state.disabledbooleanfalse禁用输入
state.errorbooleanfalse错误状态(红色边框)
state.warningbooleanfalse警告状态(黄色边框)
state.clearablebooleanfalse显示清除按钮

appearance — 视觉外观​

Prop类型默认值说明
appearance.size'sm' | 'md' | 'lg''md'尺寸预设

content — 渲染内容​

Prop类型默认值说明
content.prefixReact.ReactNode—输入框内部前插槽
content.suffixReact.ReactNode—输入框内部后插槽
content.addonBeforeReact.ReactNode—输入框外部前块(带背景)
content.addonAfterReact.ReactNode—输入框外部后块(带背景)

interaction — 事件回调​

Prop类型默认值说明
interaction.onChange(value: string, e) => void—值变化(value-first)
interaction.onPressEnter(e) => void—Enter 键按下
interaction.onFocus(e) => void—聚焦
interaction.onBlur(e) => void—失焦

override — 样式覆盖(所有组件必有)​

Prop类型默认值说明
override.classNamestring''自定义 className
override.styleCSSProperties—内联样式

a11y — 无障碍(所有组件必有)​

Prop类型默认值说明
a11y.ariaLabelstring—无障碍标签
a11y.ariaLabelledBystring—label 元素 ID
a11y.ariaDescribedBystring—描述元素 ID
a11y.roleAriaRole—自定义 ARIA role
a11y.tabIndexnumber—Tab 顺序

native — 原生 HTML 属性​

透传到 <input> 元素,支持 type、placeholder、value(受控)、defaultValue(非受控)、name、autoFocus、autoComplete、maxLength、readOnly、required、pattern、min、max 等。