Skip to content

Input ​

A controlled single-line input that supports size, disabled, readonly, clearable, password masking, and a maximum length.

Spec source: lh-ui-core/specs/input.json · Golden cases: cases/input.json (8 cases, translated into JVM unit tests + Compose UI Test)

Basic usage ​

9:41Input

HTML mock preview (Android / Compose look), not an on-device render

kotlin
var value by remember { mutableStateOf("") }
LhInput(
  value = value,
  placeholder = "请输入内容",
  onValueChange = { value = it },
)

Size and focus ​

Three sizes map to the input.height / input.paddingHorizontal / input.fontSize tokens; when focused, the border takes the color.focus color and widens to input.focusRingWidth.

9:41Input sizes

HTML mock preview (Android / Compose look), not an on-device render

API ​

Props ​

PropDescriptionTypeDefault
valueControlled value (required)String—
onValueChangeValue change callback (required)(String) -> Unit—
placeholderPlaceholder textString?null
typeInput type (plaintext / password)LhInputTypeText
lhSizeSizeLhInputSizeMedium
disabledWhether the input is disabledBooleanfalse
readonlyWhether the input is read-only (not editable, but without the disabled style)Booleanfalse
clearableWhether to show the clear buttonBooleanfalse
maxlengthMaximum length (extra input is truncated)IntInt.MAX_VALUE
lhOnFocus / lhOnBlurFocus / blur callbacks(() -> Unit)?null
prefix / suffixPrefix / suffix slots@Composable (() -> Unit)?null
modifierModifierModifierModifier

LhInputSize ​

ValueheightpaddingHorizontalfontSize
Smallinput.height.small (32dp)input.paddingHorizontal.small (12dp)input.fontSize.small (13sp)
Mediuminput.height.medium (40dp)input.paddingHorizontal.medium (16dp)input.fontSize.medium (14sp)
Largeinput.height.large (48dp)input.paddingHorizontal.large (20dp)input.fontSize.large (16sp)

Token reference ​

TokenUsage
input.height.{small,medium,large}Three heights
input.paddingHorizontal.{small,medium,large}Three horizontal paddings
input.fontSize.{small,medium,large}Three font sizes
input.borderRadius / input.borderWidth / input.focusRingWidthCorner radius / border width / focus border width
input.clearIconSizeClear icon size
color.focusFocus border color
color.text.placeholderPlaceholder text color
color.border.baseDefault border color
color.disabled.{bg,text,border}The three disabled colors

Golden case reference ​

case idAssertionLocal test
input-emits-onvaluechangeInput triggers onValueChangeLhInputTest.input_emits_onValueChange (Compose UI Test)
clearable-emits-empty-valueThe clear button emits an empty valueLhInputTest.clearable_emits_empty_value
disabled-blocks-inputThe disabled state accepts no inputLhInputTest.disabled_blocks_input
readonly-blocks-inputThe read-only state accepts no inputLhInputTest.readonly_blocks_input
placeholder-uses-placeholder-tokenThe placeholder color takes the placeholder tokenLhInputDefaultsTest.placeholder_uses_placeholder_token
focus-uses-focus-tokenFocus consumes the focus tokens (unfocused takes the neutral border)LhInputDefaultsTest.focus_uses_focus_tokens + unfocused_uses_neutral_tokens
small-size-uses-small-tokensSmall consumes the small size tokensLhInputDefaultsTest.small_size_uses_small_tokens
maxlength-truncates-inputInput beyond the maximum length is truncatedLhInputTest.maxlength_truncates_input
bash
./gradlew :components:input:test                              # JVM part
./gradlew :components:input:connectedAndroidTest              # Interaction part (requires a device)

lh-ui native bloodline · Android (Kotlin + Compose)