Input
LhInput is a form input component based on the native input element, supporting text input, password, character count, and more.
Type Definitions
The TypeScript type structures exported by this component (auto-extracted from packages/components/input/src/types.ts and @lh-ui/share/core/* sources; click each entry to expand; see the Props table above for attribute descriptions):
LhInputType
export type LhInputType = typeof LH_INPUT_TYPE_CONST[keyof typeof LH_INPUT_TYPE_CONST]LhInputSize
export type LhInputSize = typeof LH_SIZE_CONST[keyof typeof LH_SIZE_CONST]LhInputState
export type LhInputState = typeof LH_INPUT_STATE_CONST[keyof typeof LH_INPUT_STATE_CONST]LhInputProps
export interface LhInputProps {
modelValue?: string
type?: LhInputType
size?: LhInputSize
disabled?: boolean
readonly?: boolean
placeholder?: string
maxlength?: number
minlength?: number
showWordLimit?: boolean
clearable?: boolean
prefixIcon?: LhIconName
suffixIcon?: LhIconName
autofocus?: boolean
autocomplete?: string
nativeType?: string
autosize?: boolean | { minRows?: number; maxRows?: number }
resize?: 'none' | 'both' | 'horizontal' | 'vertical'
name?: string
rows?: number
tabindex?: number | string
form?: string
inputStyle?: Record<string, string>
label?: string
labelPosition?: LhInputLabelPosition
labelWidth?: string | number
themeVars?: Record<string, string>
bgPattern?: string
sx?: LhSxProps
}LhIconName (from @lh-ui/share/core/icon (svgs.d.ts))
export type LhIconName = keyof typeof LH_ICON_SVGS_CONST;Basic Usage
<script setup lang="ts">
import { ref } from 'vue'
import { LhInput } from '@lh-ui/vue3'
const value = ref('')
</script>
<template>
<LhInput v-model="value" placeholder="Please input" />
</template><script>
import { LhInput } from '@lh-ui/vue3'
export default {
components: { LhInput },
data() {
return {
value: '',
}
},
}
</script>
<template>
<LhInput v-model="value" placeholder="Please input" />
</template>Types
<script setup lang="ts">
import { ref } from 'vue'
import { LhInput } from '@lh-ui/vue3'
const text = ref('')
const password = ref('')
</script>
<template>
<LhInput v-model="text" placeholder="Text input" />
<LhInput v-model="password" type="password" show-password placeholder="Password" />
</template><script>
import { LhInput } from '@lh-ui/vue3'
export default {
components: { LhInput },
data() {
return {
text: '',
password: '',
}
},
}
</script>
<template>
<LhInput v-model="text" placeholder="Text input" />
<LhInput v-model="password" type="password" show-password placeholder="Password" />
</template>Disabled
<script setup lang="ts">
import { ref } from 'vue'
import { LhInput } from '@lh-ui/vue3'
const value = ref('')
</script>
<template>
<LhInput v-model="value" disabled placeholder="Disabled" />
</template><script>
import { LhInput } from '@lh-ui/vue3'
export default {
components: { LhInput },
data() {
return {
value: '',
}
},
}
</script>
<template>
<LhInput v-model="value" disabled placeholder="Disabled" />
</template>Word Limit
<script setup lang="ts">
import { ref } from 'vue'
import { LhInput } from '@lh-ui/vue3'
const value2 = ref('')
</script>
<template>
<LhInput v-model="value2" :maxlength="50" show-word-limit placeholder="Max 50 characters" />
</template><script>
import { LhInput } from '@lh-ui/vue3'
export default {
components: { LhInput },
data() {
return {
value2: '',
}
},
}
</script>
<template>
<LhInput v-model="value2" :maxlength="50" show-word-limit placeholder="Max 50 characters" />
</template>sx Quick Layout
Use the sx prop to quickly set spacing and sizing, without writing extra CSS.
<script setup lang="ts">
import { LhInput } from '@lh-ui/vue3'
</script>
<template>
<LhInput placeholder="Vertical margin 1, horizontal padding 2" :sx="{ my: 1, px: 2 }" />
</template><script>
import { LhInput } from '@lh-ui/vue3'
export default {
components: { LhInput },
}
</script>
<template>
<LhInput placeholder="Vertical margin 1, horizontal padding 2" :sx="{ my: 1, px: 2 }" />
</template>
sxis scaled on an8pxbase:my: 1→marginTop/marginBottom: 8px,px: 2→paddingLeft/Right: 16px. See sx Quick Layout for the full API.
Slots
<script setup lang="ts">
import { ref } from 'vue'
import { LhInput } from '@lh-ui/vue3'
const value3 = ref('')
</script>
<template>
<LhInput v-model="value3">
<template #prefix>{{ '$' }}</template>
</LhInput>
<LhInput v-model="value3">
<template #suffix>unit</template>
</LhInput>
</template><script>
import { LhInput } from '@lh-ui/vue3'
export default {
components: { LhInput },
data() {
return {
value3: '',
}
},
}
</script>
<template>
<LhInput v-model="value3">
<template #prefix>{{ '$' }}</template>
</LhInput>
<LhInput v-model="value3">
<template #suffix>unit</template>
</LhInput>
</template>Sizes & Readonly
<script setup lang="ts">
import { ref } from 'vue'
const value = ref('')
</script>
<template>
<LhInput v-model="value" size="small" placeholder="small" />
<LhInput v-model="value" size="medium" placeholder="medium" />
<LhInput v-model="value" size="large" placeholder="large" />
<LhInput v-model="value" readonly placeholder="Readonly input" />
</template><script>
export default {
data() {
return { value: '' }
},
}
</script>
<template>
<LhInput v-model="value" size="small" placeholder="small" />
<LhInput v-model="value" size="medium" placeholder="medium" />
<LhInput v-model="value" size="large" placeholder="large" />
<LhInput v-model="value" readonly placeholder="Readonly input" />
</template>Clearable
<script setup lang="ts">
import { ref } from 'vue'
const value = ref('')
</script>
<template>
<LhInput v-model="value" clearable placeholder="Enter and clear" />
</template><script>
export default {
data() {
return { value: '' }
},
}
</script>
<template>
<LhInput v-model="value" clearable placeholder="Enter and clear" />
</template>Prefix & Suffix Icons
prefix-icon / suffix-icon set the prefix/suffix icons, taking a built-in LhIcon name such as search or date.
<script setup lang="ts">
import { ref } from 'vue'
const value = ref('')
</script>
<template>
<LhInput v-model="value" prefix-icon="search" placeholder="Prefix icon" />
<LhInput v-model="value" suffix-icon="date" placeholder="Suffix icon" />
</template><script>
export default {
data() {
return { value: '' }
},
}
</script>
<template>
<LhInput v-model="value" prefix-icon="search" placeholder="Prefix icon" />
<LhInput v-model="value" suffix-icon="date" placeholder="Suffix icon" />
</template>Native Attributes & Autosize
Native attributes such as autocomplete, native-type, autofocus and minlength are passed through to the inner input; autosize makes a textarea adapt its height to the content.
<script setup lang="ts">
import { ref } from 'vue'
const value = ref('')
</script>
<template>
<LhInput v-model="value" autocomplete="off" native-type="text" :minlength="3" placeholder="autocomplete off" />
<LhInput v-model="value" autofocus placeholder="Autofocus" />
<LhInput v-model="value" type="textarea" :autosize="{ minRows: 2, maxRows: 4 }" placeholder="Autosize" />
</template><script>
export default {
data() {
return { value: '' }
},
}
</script>
<template>
<LhInput v-model="value" autocomplete="off" native-type="text" :minlength="3" placeholder="autocomplete off" />
<LhInput v-model="value" autofocus placeholder="Autofocus" />
<LhInput v-model="value" type="textarea" :autosize="{ minRows: 2, maxRows: 4 }" placeholder="Autosize" />
</template>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)
<script setup lang="ts">
import { ref } from 'vue'
const value = ref('')
</script>
<template>
<!-- Floating label (float by default): floats to the top-left notch on focus or when it has a value -->
<LhInput v-model="value" label="Name" />
<!-- Label above / below the control -->
<LhInput v-model="value" label="Name" label-position="top" />
<LhInput v-model="value" label="Name" label-position="bottom" />
<!-- Label to the left / right of the control; label-width fixes its width, only for left / right -->
<LhInput v-model="value" label="Name" label-position="left" label-width="64px" />
<LhInput v-model="value" label="Name" label-position="right" />
</template><script>
export default {
data() {
return { value: '' }
},
}
</script>
<template>
<!-- Floating label (float by default): floats to the top-left notch on focus or when it has a value -->
<LhInput v-model="value" label="Name" />
<!-- Label above / below the control -->
<LhInput v-model="value" label="Name" label-position="top" />
<LhInput v-model="value" label="Name" label-position="bottom" />
<!-- Label to the left / right of the control; label-width fixes its width, only for left / right -->
<LhInput v-model="value" label="Name" label-position="left" label-width="64px" />
<LhInput v-model="value" label="Name" label-position="right" />
</template>Props
| Prop | Description | Type | Default |
|---|---|---|---|
| modelValue | Bound value | string | — |
| type | Input type | "number" | "text" | "textarea" | "password" | "email" | "url" | "tel" | "date" | "time" | 'text' |
| size | — | "small" | "medium" | "large" | "mini" | "x-large" | 'medium' |
| disabled | Disabled state | boolean | false |
| readonly | — | boolean | false |
| placeholder | Placeholder text | string | — |
| maxlength | Maximum length | number | — |
| minlength | — | number | — |
| showWordLimit | Show character count | boolean | false |
| clearable | Show clear button | boolean | false |
| prefixIcon | Prefix icon name (a built-in LhIcon name) | "email" | "date" | "star" | "search" | "check" | "close" | "arrow-up" | "arrow-down" | "arrow-left" | "arrow-right" | "warning" | "error" | "info" | "loading" | "plus" | "minus" | "edit" | "delete" | "setting" | "user" | "home" | "menu" | "more" | "download" | "upload" | "refresh" | "folder" | "file" | "clock" | "phone" | "location" | "image" | "share" | "bell" | "filter" | "eye" | "link" | — |
| suffixIcon | Suffix icon name (a built-in LhIcon name) | "email" | "date" | "star" | "search" | "check" | "close" | "arrow-up" | "arrow-down" | "arrow-left" | "arrow-right" | "warning" | "error" | "info" | "loading" | "plus" | "minus" | "edit" | "delete" | "setting" | "user" | "home" | "menu" | "more" | "download" | "upload" | "refresh" | "folder" | "file" | "clock" | "phone" | "location" | "image" | "share" | "bell" | "filter" | "eye" | "link" | — |
| autofocus | — | boolean | false |
| autocomplete | — | string | — |
| nativeType | — | string | — |
| autosize | — | boolean | { minRows?: number; maxRows?: number; } | false |
| resize | — | "none" | "both" | "horizontal" | "vertical" | 'vertical' |
| name | — | string | — |
| rows | — | number | — |
| tabindex | — | string | number | — |
| form | — | string | — |
| inputStyle | — | { [x: string]: string; } | — |
| label | Label text (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 the left / right positions (numbers are treated as px, strings are used as-is) | string | number | — |
| themeVars | Component-level theme variables, overrides ConfigProvider | { [x: string]: string; } | — |
| bgPattern | Component-level background pattern, overrides ConfigProvider | string | — |
| sx | sx quick-layout props | LhSxProps | — |
Events
| Event | Description | Callback |
|---|---|---|
| update:modelValue | Value change | (value: string) => void |
| change | Input change | (value: string) => void |
| input | Input event | (value: string) => void |
| focus | Focus event | (e: FocusEvent) => void |
| blur | Blur event | (e: FocusEvent) => void |
| clear | Clear clicked | () => void |
| keydown | Native keydown event | (e: KeyboardEvent) => void |
Slots
| Slot | Description |
|---|---|
| prefix | Prefix content |
| suffix | Suffix content |

