# Input
Text and multiline input. Supports prefix / suffix icons, clearing, word counting, maxlength truncation, and form-validation integration.
Input variants
<template>
<div class="demo-col" style="gap: 18px">
<div class="demo-row" style="gap: 12px; flex-wrap: wrap">
<LhInput v-model="text" placeholder="请输入内容" clearable name="title" />
<LhInput v-model="text" prefix-icon="lh-icon-search" suffix-icon="lh-icon-close" placeholder="前后缀图标" />
</div>
<div class="demo-row" style="gap: 12px; flex-wrap: wrap">
<LhInput v-model="secret" type="password" placeholder="密码" autocomplete="new-password" />
<LhInput v-model="text" readonly placeholder="只读" />
<LhInput v-model="text" disabled placeholder="禁用状态" />
</div>
<div class="demo-row" style="gap: 12px; flex-wrap: wrap; align-items: center">
<LhInput v-model="text" size="small" placeholder="small" />
<LhInput v-model="text" size="medium" placeholder="medium" />
<LhInput v-model="text" size="large" placeholder="large" />
</div>
<div class="demo-row" style="gap: 12px; flex-wrap: wrap">
<LhInput v-model="poem" type="textarea" :rows="2" placeholder="多行文本(rows=2)" resize="vertical" />
<LhInput v-model="poem" type="textarea" autosize placeholder="自适应行高" />
</div>
<div class="demo-row" style="gap: 12px; flex-wrap: wrap">
<LhInput v-model="limited" :maxlength="20" show-word-limit placeholder="字数统计" />
<LhInput v-model="text" label="浮动标签" placeholder="与 placeholder 互斥" />
</div>
<p class="demo-note">当前值:{{ text || '(空)' }}</p>
</div>
</template>
<script>
export default {
data: () => ({ text: '', secret: '', poem: '', limited: '' }),
}
</script>
# Label & Floating Label
Use label to provide a control label and labelPosition to place it, with five options (default float):
float(default): floating label. The label sits inside the field as its placeholder (mutually exclusive withplaceholder); on focus or when it has a value, it floats to the notch at the field's top-left corner and shrinks. While a value remains it stays floated after blur; it only falls back when the value is clearedtop/bottom: the label is statically placed above / below the control (no floating or shrinking)left/right: the label is inline on the same row as the control, at its left / right side.labelWidthfixes the label width (only effective for these two positions; numbers are treated as px, strings are used as-is)
<template>
<!-- 浮动标签(默认 float):聚焦或有值时浮到左上缺口 -->
<LhInput v-model="value" label="姓名" />
<!-- 标签在上方 / 下方 -->
<LhInput v-model="value" label="姓名" label-position="top" />
<LhInput v-model="value" label="姓名" label-position="bottom" />
<!-- 标签在控件左 / 右侧;label-width 定宽,仅 left / right 生效 -->
<LhInput v-model="value" label="姓名" label-position="left" label-width="64px" />
<LhInput v-model="value" label="姓名" label-position="right" />
</template>
# Props
| Prop | Description | Type | Default |
|---|---|---|---|
| v-model | Bound value (model: modelValue/input) | string | — |
| type | Control type | 'text' \| 'textarea' \| 'password' \| … | 'text' |
| size | Size | 'small' \| 'medium' \| 'large' | 'medium' |
| placeholder | Placeholder text; falls back to the locale message | string | t('input.placeholder') |
| clearable | Show a clear button | boolean | false |
| prefixIcon / suffixIcon | Prefix / suffix icon class names | string | — |
| maxlength / minlength | Native length limits | number | — |
| showWordLimit | Show word count (requires maxlength) | boolean | false |
| autosize | Auto-growing textarea height | boolean \| {minRows,maxRows} | false |
| disabled / readonly | Disabled / read-only | boolean | false |
| autofocus | Focus on mount | boolean | false |
| autocomplete | Native autocomplete | string | 'off' |
| nativeType | Native type (effective when type=text) | string | 'text' |
| resize | Resize-handle direction for textarea | 'none' \| 'both' \| 'horizontal' \| 'vertical' | — |
| name / form | Native name / form attributes | string | — |
| tabindex | Native tabindex | number \| string | — |
| inputStyle | Inline style of the input element | Record<string, string> | — |
| label | Floating label (mutually exclusive with placeholder) | string | — |
| labelPosition | Label position: float (default, floating label——floats to the top-left notch on focus or when it has a value, stays floated after blur while a value remains) / top / bottom (statically above / below) / left / right (inline on the same row) | 'float' \| 'top' \| 'left' \| 'right' \| 'bottom' | 'float' |
| labelWidth | Fixed label width, only effective for left / right (numbers are treated as px, strings are used as-is) | string \| number | — |
| themeVars / bgPattern / sx | Theme overrides | — | — |
# Events
| Event | Description | Callback args |
|---|---|---|
| input | v-model event | (val, e) |
| change | Emitted when the value changes | — |
| focus | Emitted on focus | — |
| blur | Emitted on blur | — |
| clear | Emitted when cleared | — |
| keydown | Emitted on keydown | — |
# Form integration
When placed inside a LhFormItem and validation fails, the native control automatically gets aria-invalid="true".
Copyright © 2024-2026 FengMo WenXue