Input 输入框

示例

基础用法

<div>
  左边<Input class="mx-2 w-20 border-b py-1" />右边
</div>

带清除按钮

<Input clearable />

输入内容右对齐

<Input class="text-right" placeholder="请输入验证码" clearable />

只读状态

<Input readonly value="输入框的内容是只读的" />

禁用状态

<Input disabled value="被禁用的输入框" />

表单-水平布局

<script lang="ts">
  let form = $state({ username: '', password: '' })
</script>

<Form
  header="表单-水平布局"
  bind:data={form}
  layout="horizontal"
  --sunp-label-width="80px"
>
  <FormItem label="用户名" field="username" required>
    <Input
      bind:value={form.username}
      placeholder="请输入用户名"
      autocomplete="username"
    />
  </FormItem>
  <FormItem label="密码" field="password" required>
    <Input
      type="password"
      bind:value={form.password}
      placeholder="请输入密码"
      autocomplete="current-password"
    />
  </FormItem>
</Form>

表单-垂直布局

<Form header="表单-垂直布局" bind:data={form}>
  <FormItem label="用户名" field="username" required>
    <Input bind:value={form.username} placeholder="请输入用户名" />
  </FormItem>
  <FormItem label="密码" field="password" required>
    <Input bind:value={form.password} placeholder="请输入密码" />
  </FormItem>
</Form>

Input

属性

属性 说明 类型 默认值
value 输入值 string $bindable('')
type 输入框类型 [InputTypeAttribute](#input-type-attribute) 'text'
placeholder 占位文本 string undefined
maxlength 最大字符数量 number undefined
clearable 是否启用清除图标 boolean false
readonly 是否只读 boolean false
disabled 是否禁用 boolean false

类型定义

InputTypeAttribute

/** 输入框类型 */
type InputTypeAttribute =
  | 'email'
  | 'number'
  | 'password'
  | 'tel'
  | 'text'
  | 'url'

事件

事件 说明 类型
onChange 输入框内容变化时触发 (value: string) => void