Skip to content

Textarea ​

A multi-line text input. It provides an initial visible line count via Rows, grows automatically when content overflows, and supports a character counter.

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

Basic usage ​

A controlled component: the host listens to ValueChange and writes the new value back to Value.

9:41Textarea basics
青花瓷 (ceramic blue)
粉彩瓷 (famille rose)
Type a description

HTML mock preview (Windows / WinUI 3 appearance), not an on-device render

csharp
var textarea = new LhTextarea
{
    Rows = 3,
    Placeholder = "Type a description",
};
textarea.ValueChange += value => { /* Controlled: write the value back to Value */ };

Character counter ​

When ShowCount is true a character counter is drawn at the bottom right; when Maxlength is declared the format is "current / maximum", otherwise only the current length is shown. Input beyond Maxlength is truncated.

9:41Character counter
青花瓷 (ceramic blue)
3/10
青花瓷 (ceramic blue)
3

HTML mock preview (Windows / WinUI 3 appearance), not an on-device render

States ​

Disabled and Readonly both suppress ValueChange, but only Disabled renders the disabled style; when focused the border takes color.focus + textarea.focusRingWidth.

9:41Textarea states
Disabled
Focus border

HTML mock preview (Windows / WinUI 3 appearance), not an on-device render

API ​

Props ​

PropDescriptionTypeDefault
ValueChangeValue-change callback (controlled); not fired when disabled / readonlyevent Action<string>—
FocusFired when the field gains focusevent Action—
BlurFired when the field loses focusevent Action—
ValueCurrent text value (controlled)string""
PlaceholderPlaceholder hint text; takes the color.text.placeholder tokenstring""
RowsInitial visible line count; the height grows with the line count and the contentint3
DisabledWhether the input is disabled (no input accepted; renders the disabled style)boolfalse
ReadonlyWhether the input is read-only (focusable but accepts no input)boolfalse
ShowCountWhether to show the character counter at the bottom rightboolfalse
MaxlengthMaximum character count; truncates new input when exceeded and serves as the denominator of showCountint?null

Token Reference ​

TokenUsage
textarea.paddingVertical / paddingHorizontalPaddings
textarea.fontSizeFont size
textarea.borderRadius / borderWidthCorner radius and unfocused border width
textarea.focusRingWidth / color.focusFocused border width and color
textarea.countFontSize / color.text.secondaryCounter font size / color
textarea.minHeightMinimum height (the line-count-derived result is never smaller than it)
color.background.default / color.text.primaryContainer background / text color
color.text.placeholderPlaceholder text color
color.border.baseUnfocused border color
color.disabled.{bg,text}Disabled background / text
typography.lineHeight.primaryLine height (the height is derived from rows)
typography.fontFamilyChinese-style serif font stack

Golden Case Reference ​

How the 6 assertions of cases/textarea.json map to xUnit tests (tests/LhTextareaTests.cs):

case idAssertionLocal test
input-emits-onvaluechangeTyping fires onValueChangeInput_Emits_OnValueChange
disabled-blocks-inputThe disabled state does not fire and renders the disabled styleDisabled_Blocks_Input
showcount-renders-count"Current / maximum" takes the countFontSize tokenShowCount_Renders_Count
showcount-without-maxlength-renders-length-onlyWithout maxlength only the length is shownShowCount_Without_Maxlength_Renders_Length_Only
focus-uses-focus-tokenThe focused border takes the focus tokenFocus_Uses_Focus_Token
maxlength-truncates-inputInput beyond maxlength is truncatedMaxlength_Truncates_Input

Plus dark-mode suites: Dark_Colors_Come_From_Dark_Tokens / Dimensions_Are_Identical_In_Dark_Mode. Run: cd lh-ui-windows && dotnet test.

lh-ui native bloodline · Windows (C# + WinUI 3)