Skip to content

Input ​

A controlled single-line input. @Binding var value provides two-way binding; it supports plain and secure text, a clear button, a character limit, and a focus ring.

Spec source: lh-ui-core/specs/input.json · Golden cases: lh-ui-core/cases/input.json (8 entries, translated into XCTest, runnable on the macOS host)

Basic usage ​

The height aligns with Button (three input.height tokens); on focus the border switches to color.focus and widens into a focus ring.

9:41Input basic

HTML mock preview (iOS / SwiftUI appearance), not an on-device render

swift
@State private var text = ""

LhInput(value: $text, placeholder: "Please enter content") { newValue in
  // onValueChange
}

Sizes ​

Three sizes map to the input.height / paddingHorizontal / fontSize tokens.

9:41Input sizes

HTML mock preview (iOS / SwiftUI appearance), not an on-device render

Password and clear ​

type: .password lands as a SecureField (tested by testPasswordTypeIsSecure); clearable shows a clear button when there is a value, whose tap fires onValueChange("") (golden case clearable-emits-empty-value).

9:41Input extras

HTML mock preview (iOS / SwiftUI appearance), not an on-device render

swift
LhInput(value: $pwd, type: .password, clearable: true)

API ​

Props ​

PropDescriptionTypeDefault
valueInput content (controlled two-way binding)String—
placeholderPlaceholder hint textString""
typeInput type (plain text / secure text)LhInputType.text
lhSizeInput size, mapped to the size tokensLhInputSize.medium
disabledWhether disabled (fires no callbacks)Boolfalse
readonlyWhether read-only (does not fire onValueChange, keeps the focus style)Boolfalse
clearableWhether to show a clear buttonBoolfalse
maxlengthMaximum character count (excess is truncated; golden case maxlength-truncates-input)Int?nil
onValueChangeContent-change callback; the payload is the new value((String) -> Void)?nil
lhOnFocusFocus callback(() -> Void)?nil
lhOnBlurBlur callback(() -> Void)?nil

LhInputSize ​

ValueheightpaddingHorizontalfontSize
.smallinput.height.small (32pt)input.paddingHorizontal.small (12pt)input.fontSize.small (13pt)
.mediuminput.height.medium (40pt)input.paddingHorizontal.medium (16pt)input.fontSize.medium (14pt)
.largeinput.height.large (48pt)input.paddingHorizontal.large (20pt)input.fontSize.large (16pt)

LhInputType ​

ValueLands as
.textTextField
.passwordSecureField

Colors ​

StateBorderText / placeholder
Defaultcolor.border.base (input.borderWidth)color.text.primary / color.text.placeholder
Focusedcolor.focus (input.focusRingWidth)Same as above
Disabledcolor.disabled.bordercolor.disabled.text

Token Reference ​

TokenPurpose
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.borderWidthCorner radius (follows radius.small) and border width
input.focusRingWidthFocus ring width
input.clearIconSizeClear button icon size
color.focusFocus border color
color.text.{primary,placeholder,disabled}Text and placeholder colors
color.border.base / color.disabled.borderBorder colors
color.background.default / color.disabled.bgBackground colors

Golden Case Mapping ​

case idAssertionLocal test
input-emits-onvaluechangeTyping fires onValueChange("青花瓷 (ceramic blue)")testDefaultIsEditable
clearable-emits-empty-valueClearing fires onValueChange("")testClearableShowsClearButtonWhenHasValue
disabled-blocks-inputThe disabled state does not fire onValueChangetestDisabledBlocksInput
readonly-blocks-inputThe read-only state does not fire onValueChangetestReadonlyBlocksInput
placeholder-uses-placeholder-tokenThe placeholder text takes the placeholder color tokentestPlaceholderUsesPlaceholderToken
focus-uses-focus-tokenFocus consumes the focus token and fires lhOnFocustestFocusUsesFocusToken
small-size-uses-small-tokensThe small size consumes the small size tokenstestSmallSizeUsesSmallTokens
maxlength-truncates-inputExcess characters are truncatedtestMaxlengthTruncatesInput

Plus dedicated tests: testPasswordTypeIsSecure / testDarkColorsComeFromDarkTokens / testDimensionsAreIdenticalInDarkMode / testInputViewInitAcceptsConstant.

bash
swift test --filter LhInputTests    # Runs on the macOS host, no simulator required

lh-ui native bloodline · iOS (Swift + SwiftUI)