Input
单行文本输入,通过鼠标或键盘输入内容。
使用
ts
import { NxInput } from "@pc-nexus/angular";ts
import { NxInput } from "@pc-nexus/react";属性
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
value | string | 当前输入值(表单协议) | |
placeholder | string | 占位文案 | |
size | 'small' | 'medium' | 'large' | 尺寸,默认 medium | |
appearance | 'outline' | 'fill' | 'subtle' | 'ghost' | 外观,默认 outline | |
type | string | 原生 input type,如 text、number、password | |
readonly | boolean | 只读,默认 false | |
disabled | boolean | 禁用,默认 false | |
maxlength | number | 最大输入长度 | |
minlength | number | 最小输入长度 | |
min | number | string | 最小值(常用于 type="number") | |
max | number | string | 最大值(常用于 type="number") | |
step | number | string | 步进值(常用于 type="number") | |
required | boolean | 是否必填,默认 false | |
autofocus | boolean | 自动聚焦,默认 false | |
id | string | 元素 id | |
name | string | 原生 name |
事件
| 名称 | 类型 | 描述 |
|---|---|---|
valueChange | (value: string) | 输入值变化时触发 |
focus | (event: Event) | 获得焦点时触发 |
blur | (event: Event) | 失去焦点时触发 |
示例
Basic
通过 value 绑定当前文本,并用 valueChange 监听变化。Angular 可使用 [(value)];React 需配合 onValueChange 更新状态。
Appearance
通过 appearance 设置外观,取值可以为 'outline' | 'fill' | 'subtle' | 'ghost'。
Size
通过 size 设置尺寸,取值可以为 'small' | 'medium' | 'large'。
Type
通过 type 设置原生 input 类型,如 text、number、password。
Limit
通过 minlength / maxlength 限制文本长度,或通过 min / max 限制数值范围。
Readonly
通过 readonly 设为只读。
Disabled
通过 disabled 禁用输入。