Skip to content

Textarea ​

Multi-line text input. The height grows with the number of rows and the content, and it supports a character counter and a character limit.

Spec source: lh-ui-core/specs/textarea.json · Golden cases: lh-ui-core/cases/textarea.json (6 cases, translated into hypium tests)

Basic usage ​

rows decides the initial number of visible rows, and the minimum height comes from the textarea.minHeight token.

9:41Textarea basics

HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render

typescript
LhTextarea({
  value: this.remark,
  placeholder: 'Please enter remarks',
  rows: 3,
  onValueChange: (value: string) => { this.remark = value },
})

Character counter ​

When showCount is true, a character counter is shown in the bottom-right corner: with maxlength set, it displays current/limit; without it, only the current length is shown.

9:41Textarea counter
46/50
0

HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render

API ​

Props ​

PropDescriptionTypeDefault
valueCurrent text value (controlled)string''
placeholderPlaceholder hint textstring''
rowsInitial number of visible rows; the height grows with rows and contentnumber3
disabledWhether disabled; ignores input and does not fire onValueChange when disabledbooleanfalse
readonlyWhether read-only; focusable but accepts no input when read-onlybooleanfalse
showCountWhether to show the character counter in the bottom-right cornerbooleanfalse
maxlengthMaximum character count; excess input is truncated; the denominator when showCount is onnumber?undefined
onValueChangeFired when the text changes; not fired when disabled / readonly(value: string) => voidEmpty function
onFocusFired when focus is gained() => voidEmpty function
onBlurFired when focus is lost() => voidEmpty function

Token reference ​

TokenPurpose
textarea.minHeightMinimum height when empty (72vp, roughly three rows)
textarea.paddingHorizontal / textarea.paddingVerticalPaddings (12 / 12vp)
textarea.fontSizeInput font size (14)
textarea.countFontSizeCounter font size (12)
textarea.borderRadius / textarea.borderWidthCorner radius and border width
textarea.focusRingWidthFocus ring width
typography.lineHeight.primaryLine height (1.8)
color.text.primary / color.text.placeholderInput text / placeholder text color
color.background.default / color.background.disabledBackground / disabled background color
color.border.base / color.focusBorder color / focus color

Golden case reference ​

How the 6 assertions in cases/textarea.json map onto hypium tests (entry/src/test/Textarea.test.ets):

case idAssertionLocal test
input-emits-onvaluechangeTyping fires onValueChangedisabled_is_not_interactive (inverse gate assertion)
disabled-blocks-inputDisabled state ignores inputdisabled_is_not_interactive
showcount-renders-countThe counter renders current/limitshowcount_renders_count_with_maxlength
showcount-without-maxlength-renders-length-onlyWithout a limit, only the length is shownshowcount_renders_length_only_without_maxlength
focus-uses-focus-tokenFocused state uses the focus tokenfocus_uses_focus_token
maxlength-truncates-inputInput beyond the limit is truncatedmaxlength_truncates_input

Plus dark-mode specifics: dark_colors_come_from_dark_tokens / dimensions_are_identical_in_dark_mode. To run: in DevEco Studio, right-click entry/src/test → Run Tests.

lh-ui native bloodline · HarmonyOS (ArkTS + ArkUI)