Skip to content

HyTextArea ​

Usage examples on this page are written for Lit / plain HTML (<hy-text-area>). The same component ships as HyTextArea in @whitespaceux/harmony-react (native React 19), with typed wrappers for Angular, Solid, Svelte, and Vue. The API reference below applies to all frameworks.

A versatile multi-line text input component with enhanced styling and functionality. Supports validation states, auto-resizing, character limits, and comprehensive accessibility features. Provides a consistent interface for various text area scenarios with built-in error handling.

When to use

  • Free text over several lines: a comment, a description, a message.

Do

  • Set rows to the length most answers have.

When not to use

  • A name, an email or a search term: hy-text-input.
  • A value from a known set: hy-select or hy-combobox.
  • An address or another multi-part record: one labeled hy-text-input per part.
  • Text that needs headings, lists or emphasis: hy-markdown-editor.
  • Answers whose length varies widely: auto-resize, capped with max-rows, instead of scrolling in a fixed box.

Accessibility: your part ​

  • Name the field with label, or with aria-label / aria-labelledby on the host when nearby text already names it.
  • Never put instructions in placeholder. It disappears on the first keystroke.
  • When maxlength is set, tell people the limit before they reach it.

Examples ​

html
<hy-text-area label="Comments" placeholder="Enter your comments..."></hy-text-area>
html
<hy-text-area
  label="Description"
  helper-text="Provide a detailed description"
  rows="6"
  maxlength="500"
  required
>
</hy-text-area>
html
<hy-text-area
  label="Bio"
  helper-text="A few sentences about you"
  warning-message="Long bios are cut off on profile cards"
>
</hy-text-area>
<hy-text-area label="Reason" required error-message="Tell us why you are leaving"></hy-text-area>

Narrower than its container — cols states how many characters a line holds ​

html
<hy-text-area label="Address" cols="32" rows="3"></hy-text-area>
html
<hy-text-area label="Feedback" value="This is existing feedback" size="large" auto-resize>
</hy-text-area>

API ​

Properties ​

PropertyAttributeTypeDefaultDescription
focusedfocusedbooleanfalseWhether the text area is currently focused.
disableddisabledbooleanfalseDisables the text area, preventing user interaction.
requiredrequiredbooleanfalseMarks the text area as required for form validation.
readonlyreadonlybooleanfalseMakes the text area read-only, preventing user editing.
errorerrorbooleanfalseWhether the text area is in an error state.
warningwarningbooleanfalseWarning state: the value is accepted but worth a second look. Paints the warning color and shows warning-message; never sets aria-invalid and never blocks submission. error wins when both are set.
sizesize'small' | 'medium' | 'large''medium'The size of the text area: 'small', 'medium', or 'large'.
labellabelstring''The label text displayed above the text area.
valuevaluestring''The current value of the text area.
placeholderplaceholderstring''Placeholder text displayed when the text area is empty.
helperTexthelper-textstring''Helper text displayed below the text area to provide additional context.
namenamestring''The name attribute for form submission.
autocompleteautocompletestring''The autocomplete attribute for browser auto-completion.
autofocusautofocusbooleanfalseMarks this text area as the auto-focus target. Read by hy-dialog (and other overlay containers) on show to choose initial focus. Also focuses on first connect when used outside an overlay, mirroring native HTML autofocus but routed through JS so SSR'd HTML doesn't pull focus during hydration.
autoselectautoselectbooleanfalseAfter auto-focus lands, selects the current value so the user can type-to-replace. Pairs with autofocus for rename-style dialogs where the existing value is shown for context but is meant to be overwritten.
errorMessageerror-messagestring''Error message shown under the text area (replaces the helper text). Setting it raises error, clearing it lowers it.
warningMessagewarning-messagestring''Warning message shown under the text area (replaces the helper text). Setting it raises warning.
maxlengthmaxlengthnumber | undefined—Maximum number of characters allowed in the text area.
minlengthminlengthnumber | undefined—Minimum number of characters required in the text area.
rowsrowsnumber4Number of visible text lines in the text area.
colscolsnumber | undefinedundefinedHow many characters a line holds — the way to make a text area narrower than its container. One of 1–8, 10, 12, 16, 20, 24, 32, 48 (the set every field's character width shares). The textarea's content box is that many 0 glyphs in its own font (1ch plus the letter-spacing its size applies), plus its inline padding and border, so the same markup holds the same count in every design system; never wider than its container. A value outside the set is ignored — the text area fills its container, as it does without cols — and warned about in dev. Forwarded to the native <textarea> too.
wrapwrapstring'soft'How text wraps in the text area: 'soft', 'hard', or 'off'.
autoResizeauto-resizebooleanfalseAutomatically adjusts height based on content when enabled.
maxRowsmax-rowsnumber | undefined—Caps auto-resize growth at this many text rows; past the cap the textarea scrolls internally instead of growing further. No effect unless auto-resize is set. When omitted, auto-resize grows unbounded.
form—HTMLFormElement | null——
validity—ValidityState——
validationMessage—string——

Events ​

EventDetailDescription
input—Fired when the text area value changes, includes current value
change—Fired when the text area loses focus after a value change, includes current value
focus—Fired when the text area receives focus
blur—Fired when the text area loses focus

CSS Parts ​

PartDescription
baseThe text area's base wrapper element
labelThe label element
containerThe text area container element
textareaThe native textarea element
helper-textThe helper text element
error-messageThe error message element
warning-messageThe warning message element
message-iconThe icon starting the error or warning message

CSS Custom Properties ​

The documented hooks. Every override hook the component reads — one per token it paints — is listed in @whitespaceux/harmony/theme-api.json, and @whitespaceux/harmony/component-bindings.json (the Harmony MCP get-bindings tool) says which part and state each one paints.

PropertyDefaultDescription
--hy-text-area-background-surface-basevar(--hy-background-surface-base)Background color
--hy-text-area-border-subtle-restvar(--hy-border-subtle-rest)Border color at rest
--hy-text-area-border-brand-restvar(--hy-border-brand-rest)Focused edge color, any focus method.
--hy-text-area-border-default-hovervar(--hy-border-default-hover)Border color on hover
--hy-text-area-border-danger-restvar(--hy-border-danger-rest)Border color in error state
--hy-text-area-border-warning-restvar(--hy-border-warning-rest)Border color in warning state (at rest; any focus keeps the normal focus edge)
--hy-text-area-foreground-warning-restvar(--hy-foreground-warning-rest)Warning message text and icon color
--hy-text-area-gap-layout-2xsvar(--hy-gap-layout-2xs)Gap between the message icon and its text
--hy-text-area-stroke-smvar(--hy-stroke-sm)Border width
--hy-text-area-radius-form-mdvar(--hy-radius-form-md)Border radius
--hy-text-area-padding-layout-lgvar(--hy-padding-layout-lg)Horizontal padding
--hy-text-area-control-height-smvar(--hy-control-height-sm)1-row control height at small size.
--hy-text-area-control-height-mdvar(--hy-control-height-md)1-row control height at medium size.
--hy-text-area-control-height-lgvar(--hy-control-height-lg)1-row control height at large size.
--hy-text-area-padding-vertical-sm—Vertical padding at small size. Default derives from the control height so one row lands on the contract
--hy-text-area-padding-vertical-md—Vertical padding at medium size. Default derives from the control height so one row lands on the contract
--hy-text-area-padding-vertical-lg—Vertical padding at large size. Default derives from the control height so one row lands on the contract
--hy-text-area-gap-form-lgvar(--hy-gap-form-lg)Gap between label and textarea
--hy-text-area-min-height-sm—Minimum height for small size. Default: one contract row (the control height minus borders)
--hy-text-area-min-height-md—Minimum height for medium size. Default: one contract row (the control height minus borders)
--hy-text-area-min-height-lg—Minimum height for large size. Default: one contract row (the control height minus borders)

Methods ​

focus() ​

Sets focus on the text area.

blur() ​

Removes focus from the text area.

select() ​

Selects all text in the text area.

Built with Lit. Documented with VitePress.