Skip to main content

Input

Accepts manually entered and validated content, with controlled / uncontrolled modes, a character counter, clearing, and auto-growing textareas.

Basic usage​

Controlled input

Current value: (empty)

import { useState } from 'react'
import { LhInput } from '@lh-ui/react'

export default function Demo() {
const [value, setValue] = useState('')

return <LhInput value={value} onChange={(val) => setValue(val)} placeholder="Controlled input" />
}

Features​

Clearable / character limit / password / auto-growing textarea
0/10
import { LhInput } from '@lh-ui/react'

export default function Demo() {
return (
<>
<LhInput placeholder="Clearable" clearable />
<LhInput placeholder="Character limit" maxlength={10} showWordLimit />
<LhInput placeholder="Password" type="password" />
<LhInput
placeholder="Textarea"
type="textarea"
autosize={{ minRows: 2, maxRows: 4 }}
/>
</>
)
}

Label position​

labelPosition offers five positions: float / top / bottom / left / right. float (the default) is a floating label that rises to the top-left notch on focus or once a value is entered, and does not fall back while a value remains; top / bottom place it statically above / below; left / right keep it inline on the same row as the control, with labelWidth for fixed-width alignment.

Five label positions
import { LhInput } from '@lh-ui/react'

export default function Demo() {
return (
<>
{/* float (default): floating label */}
<LhInput label="Username" />
{/* top / bottom: static above / below */}
<LhInput label="Top label" labelPosition="top" />
<LhInput label="Bottom label" labelPosition="bottom" />
{/* left / right: inline on the same row as the control, aligned via labelWidth */}
<LhInput label="Left label" labelPosition="left" labelWidth={80} />
<LhInput label="Right label" labelPosition="right" labelWidth={80} />
</>
)
}

Input Props​

PropDescriptionTypeOptionsDefault
valueControlled valuestring——
defaultValueUncontrolled default valuestring——
typeNative type'text' | 'password' | 'number' | 'email' | 'tel' | 'url' | 'search' | 'textarea' | ...—'text'
placeholderPlaceholderstring—Locale pack fallback (en-US: Please enter)
disabledWhether to disableboolean—false
readonlyWhether to be read-onlyboolean—false
maxlengthMaximum input length (truncated when exceeded)number——
showWordLimitWhether to show the character counterboolean—false
clearableWhether to be clearableboolean—false
showPasswordPassword visibility toggle (renders an eye button in the suffix when type is password; a React-first feature)boolean—false
autosizeAuto-growing textarea heightboolean | { minRows?: number; maxRows?: number }—false
labelFloating labelstring——
labelPositionLabel position: float = floating label (rises to the top-left notch on focus / once there is a value, and does not fall back while a value remains); top / bottom = static above / below; left / right = inline on the same row as the control'float' | 'top' | 'left' | 'right' | 'bottom'—'float'
labelWidthFixed label width (only effective for left / right; numbers are treated as px, strings are used as-is)string | number——
prefixIcon / suffixIconPrefix / suffix iconsLhIconName——
sizeSize'large' | 'middle' | 'small'—Follows ConfigProvider
nameNative name attributestring——
themeVarsComponent-level theme variablesRecord<string, string>——
sxShorthand layout propsSxProps——

Input events​

EventDescriptionCallback signatureVue equivalent
onChangeValue change (two arguments)(value: string, event: ChangeEvent) => void@change
onInputNative input event(event: InputEvent) => void@input
onFocusGains focus(event: FocusEvent) => void@focus
onBlurLoses focus(event: FocusEvent) => void@blur
onClearClear button click(event: MouseEvent) => void@clear
onKeyDownNative keyboard event(event: KeyboardEvent) => void@keydown
The two arguments of onChange

onChange(value, event) is isomorphic with lh-ui-plus's emit('change', [val, e]), easing migration. See the migration guide.

ref​

forwardRef<HTMLInputElement | HTMLTextAreaElement> — the focusable native element.

Styles​

import '@lh-ui/react/style/input'