Textarea
The Textarea component is a multi-line text input with options for a label, caption, character counter, resizing behaviour, validation states, and an info tooltip.
Variations
Disabled
Resizable
Auto resize
The Textarea component supports automatic height adjustment based on content with the autoResize prop. When enabled, the textarea grows and shrinks to fit its content, eliminating the need for manual scrolling.
autoResize uses the native CSS field-sizing: content when the browser supports it, and respects a maximum height limit to prevent excessive growth. It may not work as expected in Firefox, which does not yet support field-sizing: content.
Theme
Textarea derives its visual state from error and warning: passing an error message applies the danger theme, and passing a warning message applies the warning theme. You can also set theme directly (warning) to colour the field without a message.
Character limit
The Textarea component supports a maxCharacters prop, which shows a live used / max counter beside the label. The counter is informational — it does not block typing past the limit.
Sizes
The Textarea component supports the sizes sm and md. The default size is md.
With tooltip
tooltipContent sets the content of the label’s info tooltip. tooltipProps passes additional props to the tooltip.
Orientation
The Textarea component accepts an optional orientation prop, which defines the layout direction of the textarea and its label. Available options are horizontal and vertical (default).
Installation
import { Textarea } from "@harnessio/ui/components";
<Textarea label="Textarea label" placeholder="Placeholder" name="textarea-name" onChange={handleChange}/>;Anatomy
Textarea composes a label, the multi-line input, and a caption inside a control group.
- The
labelrenders above (or beside, whenorientation="horizontal") the textarea. WhenmaxCharactersis set, a liveused / maxcounter renders alongside it. - The
<textarea>itself accepts standard textarea attributes such asrows,placeholder, andname. - Below the textarea, a caption area shows the
errormessage (in thedangertheme), then thewarningmessage (in thewarningtheme), otherwise the plaincaption. - Every textarea gets an
id; if you don’t provide one it’s generated automatically and used to associate the label.
Best practices
Do
- Give every textarea a clear
label(or anaria-labelwhen there’s no visible text). - Use
errorfor validation messages — it both shows the message and switches the field to thedangertheme, so you don’t need to setthemeyourself. - Reach for
autoResizewhen the expected content length varies a lot, so the field grows with the input instead of forcing a scroll. - Add
optionalto fields that aren’t required so the required*marker reflects reality.
Don’t
- Don’t rely on
maxCharactersto enforce a limit — pair it with your own validation. - Don’t set both
resizableandautoResizeexpecting them to combine cleanly;autoResizealready manages height.
Content
- Keep labels short and noun-based; put format or length guidance in the
caption. - Write
errormessages as a clear, actionable statement of what to fix.
Accessibility
Labeling
- The
labelis associated with the textarea through a sharedid(auto-generated when omitted), so clicking the label focuses the field. - When there’s no visible label, provide an
aria-label. - The character counter uses
role="status"so assistive tech can announce the remaining count as it updates.
Focus & states
disableddisables the field and removes it from the tab order.errorapplies thedangertheme and renders the message beneath the field so the validation state is both visible and adjacent to the input.
Properties
Prop | Required | Default | Type |
|---|---|---|---|
| label | false | string | |
| caption | false | string | |
| error | false | string | |
| warning | false | string | |
| theme | false | 'default' | 'default' | 'danger' | 'warning' |
| optional | false | false | boolean |
| size | false | 'md' | 'sm' | 'md' |
| maxCharacters | false | number | |
| autoResize | false | false | boolean |
| resizable | false | false | boolean |
| disabled | false | false | boolean |
| orientation | false | 'vertical' | 'vertical' | 'horizontal' |
| value | false | string | |
| defaultValue | false | string | |
| onChange | false | React.ChangeEventHandler<HTMLTextAreaElement> | |
| name | false | string | |
| id | false | string | |
| tooltipContent | false | Exclude<ReactNode, boolean | null | undefined> | |
| tooltipProps | false | IconWithTooltipProps | |
| labelSuffix | false | ReactNode | |
| className | false | string | |
| inputGroupClassName | false | string | |
| wrapperClassName | false | string |