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.disabled | boolean | false | 禁用输入 |
state.error | boolean | false | 错误状态(红色边框) |
state.warning | boolean | false | 警告状态(黄色边框) |
state.clearable | boolean | false | 显示清除按钮 |
appearance — 视觉外观
| Prop | 类型 | 默认值 | 说明 |
|---|---|---|---|
appearance.size | 'sm' | 'md' | 'lg' | 'md' | 尺寸预设 |
content — 渲染内容
| Prop | 类型 | 默认值 | 说明 |
|---|---|---|---|
content.prefix | React.ReactNode | — | 输入框内部前插槽 |
content.suffix | React.ReactNode | — | 输入框内部后插槽 |
content.addonBefore | React.ReactNode | — | 输入框外部前块(带背景) |
content.addonAfter | React.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.className | string | '' | 自定义 className |
override.style | CSSProperties | — | 内联样式 |
a11y — 无障碍(所有组件必有)
| Prop | 类型 | 默认值 | 说明 |
|---|---|---|---|
a11y.ariaLabel | string | — | 无障碍标签 |
a11y.ariaLabelledBy | string | — | label 元素 ID |
a11y.ariaDescribedBy | string | — | 描述元素 ID |
a11y.role | AriaRole | — | 自定义 ARIA role |
a11y.tabIndex | number | — | Tab 顺序 |
native — 原生 HTML 属性
透传到 <input> 元素,支持 type、placeholder、value(受控)、defaultValue(非受控)、name、autoFocus、autoComplete、maxLength、readOnly、required、pattern、min、max 等。