Skip to content

Textarea ​

A controlled multi-line input. @Binding var value provides two-way binding, plus a placeholder hint and a character counter.

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

Basic usage ​

The minimum height comes from textarea.minHeight, the padding from textarea.paddingHorizontal / paddingVertical, and on focus the border switches to color.focus.

9:41Textarea basic

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

swift
@State private var text = ""

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

Character counter ​

When showCount = true, a counter is shown in the bottom-right corner: if maxlength is set it shows current/limit (golden case showcount-renders-count); without it, only the current length is shown (showcount-without-maxlength-renders-length-only).

9:41Textarea counter
3/10

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

swift
LhTextarea(value: $text, showCount: true, maxlength: 10)

API ​

Props ​

PropDescriptionTypeDefault
valueInput content (controlled two-way binding)String—
placeholderPlaceholder hint textString""
rowsExpected number of rows (affects the minimum height)Int3
disabledWhether disabled (fires no callbacks)Boolfalse
readonlyWhether read-only (does not fire onValueChange, keeps the focus style)Boolfalse
showCountWhether to show the character counterBoolfalse
maxlengthMaximum character count (excess is truncated)Int?nil
onValueChangeContent-change callback; the payload is the new value((String) -> Void)?nil
lhOnFocusFocus callback(() -> Void)?nil
lhOnBlurBlur callback(() -> Void)?nil

Colors ​

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

Token Reference ​

TokenPurpose
textarea.minHeightMinimum height
textarea.paddingHorizontal / textarea.paddingVerticalPadding
textarea.fontSizeFont size
textarea.countFontSizeCounter text font size
textarea.borderRadius / textarea.borderWidthCorner radius and border width
textarea.focusRingWidthFocus ring width
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
disabled-blocks-inputThe disabled state does not fire onValueChangetestDisabledBlocksInput
showcount-renders-countThe counter shows 3/10 and consumes the counter font-size tokentestShowCountRendersCount
showcount-without-maxlength-renders-length-onlyWithout a limit, only 3 is showntestShowCountWithoutMaxlengthRendersLengthOnly
focus-uses-focus-tokenFocus consumes the focus token and fires lhOnFocustestFocusUsesFocusToken
maxlength-truncates-inputExcess characters are truncatedtestMaxlengthTruncatesInput

Plus dedicated tests: testLayoutUsesTextareaTokens / testReadonlyBlocksInputButKeepsFocusStyle / testDarkColorsComeFromDarkTokens / testDimensionsAreIdenticalInDarkMode / testTextareaViewInitAcceptsConstant.

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

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