Skip to content

Input ​

文本输入。v-model;label / description / error;可对接 TanStack Vue Form Field(不 peer 依赖 tanstack)。

基础 ​

标准受控输入

当前值:(空)

vue
<script setup lang="ts">
import { ref } from 'vue'
import { HInput } from 'happier-ui'

const name = ref('')
</script>

<template>
  <h-input
    v-model="name"
    label="名称"
    description="标准受控输入"
    placeholder="输入名称"
  />
</template>

TanStack Vue Form ​

库不依赖 @tanstack/vue-form。在宿主用 Field 绑定:

vue
<form.Field name="email">
  <template #default="{ field }">
    <h-input
      label="Email"
      :name="field.name"
      :model-value="String(field.state.value ?? '')"
      @update:model-value="field.handleChange"
      @blur="field.handleBlur"
    />
  </template>
</form.Field>

API ​

Props ​

名称类型默认说明
modelValuestring | number''受控值
typestring'text'input type
namestring—表单 name
idstring自动关联 label
labelstring—标签文案
descriptionstring—辅助说明
errorstring—错误文案(同时倾向 invalid)
placeholderstring—占位
disabledbooleanfalse禁用
readonlybooleanfalse只读
autocompletestring—原生 autocomplete
inputmode'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'—输入模式
invalidboolean由 error 推断显式校验态
size'sm' | 'md' | 'lg''md'尺寸

Emits ​

事件载荷说明
update:modelValuestring输入变化
blurFocusEvent失焦

Slots ​

无。

无障碍 ​

  • label 与 input 关联
  • aria-invalid / aria-describedby(description / error)

MIT License