Skip to content
API 风格:

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
ts
export type LhInputType = typeof LH_INPUT_TYPE_CONST[keyof typeof LH_INPUT_TYPE_CONST]
LhInputSize
ts
export type LhInputSize = typeof LH_SIZE_CONST[keyof typeof LH_SIZE_CONST]
LhInputState
ts
export type LhInputState = typeof LH_INPUT_STATE_CONST[keyof typeof LH_INPUT_STATE_CONST]
LhInputProps
ts
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))
ts
export type LhIconName = keyof typeof LH_ICON_SVGS_CONST;

Basic Usage ​

Basic Usage
vue
<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>
vue
<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 ​

Types
vue
<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>
vue
<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 ​

Disabled
vue
<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>
vue
<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 ​

Word Limit
0/50
vue
<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>
vue
<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.

sx spacing
vue
<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>
vue
<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>

sx is scaled on an 8px base: my: 1 → marginTop/marginBottom: 8px, px: 2 → paddingLeft/Right: 16px. See sx Quick Layout for the full API.

Slots ​

Slots
vue
<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>
vue
<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 ​

Sizes & Readonly
vue
<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>
vue
<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 ​

Clearable
vue
<script setup lang="ts">
import { ref } from 'vue'

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

<template>
  <LhInput v-model="value" clearable placeholder="Enter and clear" />
</template>
vue
<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.

Prefix & Suffix Icons
vue
<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>
vue
<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.

Native Attributes & Autosize
vue
<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>
vue
<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 with placeholder); 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 cleared
  • top / 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. labelWidth fixes the label width (only effective for these two positions; numbers are treated as px, strings are used as-is)
Label positions
vue
<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>
vue
<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 ​

PropDescriptionTypeDefault
modelValueBound valuestring—
typeInput type"number" | "text" | "textarea" | "password" | "email" | "url" | "tel" | "date" | "time"'text'
size—"small" | "medium" | "large" | "mini" | "x-large"'medium'
disabledDisabled statebooleanfalse
readonly—booleanfalse
placeholderPlaceholder textstring—
maxlengthMaximum lengthnumber—
minlength—number—
showWordLimitShow character countbooleanfalse
clearableShow clear buttonbooleanfalse
prefixIconPrefix 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"—
suffixIconSuffix 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—booleanfalse
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; }—
labelLabel text (floating label, mutually exclusive with placeholder)string—
labelPositionLabel 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'
labelWidthFixed label width, only effective for the left / right positions (numbers are treated as px, strings are used as-is)string | number—
themeVarsComponent-level theme variables, overrides ConfigProvider{ [x: string]: string; }—
bgPatternComponent-level background pattern, overrides ConfigProviderstring—
sxsx quick-layout propsLhSxProps—

Events ​

EventDescriptionCallback
update:modelValueValue change(value: string) => void
changeInput change(value: string) => void
inputInput event(value: string) => void
focusFocus event(e: FocusEvent) => void
blurBlur event(e: FocusEvent) => void
clearClear clicked() => void
keydownNative keydown event(e: KeyboardEvent) => void

Slots ​

SlotDescription
prefixPrefix content
suffixSuffix content

Beauty of tradition, foundation of code