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.
label, placeholder, and caption cover the text around the field, while error and warning show a validation message and switch the theme (otherwise set theme directly). rows sets the starting height, resizable lets the user drag to resize, and autoResize grows the field to fit its content. maxCharacters shows a used / max counter, and orientation places the label above or beside the field. Try them in the playground below.
Variations
With tooltip
tooltipContent sets the content of the label’s info tooltip (available as a control in the playground above). Pass tooltipProps to customise the tooltip — for example, swapping its icon:
Mention textarea
MentionTextarea extends Textarea with an inline suggestion menu. Typing the triggerChar (default @) opens a list of items at the caret; selecting one inserts formatMention(item) (default @[value]). It is controlled through value / onValueChange and accepts all Textarea props.
import { MentionTextarea } from "@harnessio/ui/components";
<MentionTextarea value={value} onValueChange={setValue} items={[{ id: "1", value: "alice", label: "Alice Smith" }]}/>;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 |
MentionTextarea
Accepts every Textarea prop except onChange, plus:
Prop | Required | Default | Type |
|---|---|---|---|
| value | true | string | |
| onValueChange | true | (value: string) => void | |
| items | true | { id: string; value: string; label?: string }[] | |
| triggerChar | false | '@' | string |
| isLoading | false | false | boolean |
| loadingContent | false | ReactNode | |
| emptyMessage | false | 'No results found' | ReactNode |
| onSearchChange | false | (query: string) => void | |
| onItemSelect | false | (item) => void | |
| formatMention | false | `@[${item.value}]` | (item) => string |
| renderItem | false | (item) => ReactNode |