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 }}
/>
</>
)
}

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——
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'