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.

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="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.
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 displayed when the text area is in an invalid state.
maxlengthmaxlengthnumber | undefinedMaximum number of characters allowed in the text area.
minlengthminlengthnumber | undefinedMinimum number of characters required in the text area.
rowsrowsnumber4Number of visible text lines in the text area.
colscolsnumber | undefinedNumber of visible character columns in the text area.
wrapwrapstring'soft'How text wraps in the text area: 'soft', 'hard', or 'off'.
autoResizeauto-resizebooleanfalseAutomatically adjusts height based on content when enabled.
maxRowsmax-rowsnumber | undefinedCaps 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.
formHTMLFormElement | null
validityValidityState
validationMessagestring

Events

EventDetailDescription
inputFired when the text area value changes, includes current value
changeFired when the text area loses focus after a value change, includes current value
focusFired when the text area receives focus
blurFired 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

CSS Custom Properties

PropertyDescription
--hy-text-area-background-restBackground color
--hy-text-area-border-restBorder color at rest
--hy-text-area-border-activeFocused edge color, any focus method. Default: var(--hy-border-brand-rest)
--hy-text-area-border-hoverBorder color on hover
--hy-text-area-border-dangerBorder color in error state
--hy-text-area-strokeBorder width
--hy-text-area-radiusBorder radius
--hy-text-area-padding-horizontalHorizontal padding
--hy-text-area-height-sm1-row control height at small size. Default: var(--hy-control-height-sm)
--hy-text-area-height-md1-row control height at medium size. Default: var(--hy-control-height-md)
--hy-text-area-height-lg1-row control height at large size. Default: var(--hy-control-height-lg)
--hy-text-area-padding-vertical-smVertical padding at small size. Default derives from the control height so one row lands on the contract
--hy-text-area-padding-vertical-mdVertical padding at medium size. Default derives from the control height so one row lands on the contract
--hy-text-area-padding-vertical-lgVertical padding at large size. Default derives from the control height so one row lands on the contract
--hy-text-area-gapGap between label and textarea
--hy-text-area-font-familyFont family override for the textarea value text
--hy-text-area-min-height-smMinimum height for small size. Default: one contract row (the control height minus borders)
--hy-text-area-min-height-mdMinimum height for medium size. Default: one contract row (the control height minus borders)
--hy-text-area-min-height-lgMinimum 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.