Skip to main content

InputTag

Enter multiple items as tags: Enter / comma / space commits a tag, Backspace on empty input removes the last one.

Basic usage​

Basic usage
水墨留白

Current tags:水墨、留白

只读
禁用
import { LhInputTag } from '@lh-ui/react'

export default function Demo() {
return (
<LhInputTag
defaultValue={['Ink wash', 'Blank space']}
placeholder="Type and press Enter to create a tag"
/>
)
}

InputTag Props​

PropDescriptionTypeOptionsDefault
value / defaultValueTag list (controlled / uncontrolled)string[]——
onChangeTag list changed(value: string[]) => void——
onAddA single tag committed(tag: string) => void——
onRemoveA single tag removed(tag: string) => void——
triggerKey that commits a tagLhInputTagTrigger'enter' | 'space' | 'comma''enter'
placeholderPlaceholder (shown only when there are no tags)string—''
maxTag limit (non-positive = unlimited)number—0
allowDuplicateAllow duplicate tagsboolean—false
readonlyRead-only (no tags created, delete keys ignored)boolean—false
disabledDisabledboolean—false
ariaLabelAccessible name (falls back to locale pack inputTag.label)string——
sxShorthand layout propsSxProps——

Ref (LhInputTagInstance)​

MethodDescription
focus()Focus the input (clicking the container does the same)
commit()Commit the current input
Commit semantics

Empty input is silently ignored; on duplicate / over-limit the input is cleared without firing onChange — business layers sense it via onAdd / onRemove.

Accessibility

The input's aria-label comes from the locale pack (overridable via ariaLabel); the remove button's aria-label uses the locale pack ariaLabels.removeTag.

Styles​

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