Form textarea
Captures multi-line text with optional automatic height and character counting.
On this page
This docs is LLM-friendly and available as clean Markdown.
Supported browser agents can also use WebMCP to search, read, and open these docs. Learn more
Usage
import { GlFormTextarea } from "gitlab-ui-react/form-textarea";<GlFormTextarea aria-label="Description" />Default
Use a textarea for multi-line input. It starts at four rows and prevents manual resizing by default.
Textarea
import { GlFormField, GlFormFieldLabel } from "gitlab-ui-react/form-field";
import { GlFormTextarea } from "gitlab-ui-react/form-textarea";
export default function FormTextareaExample() {
return (
<GlFormField className="max-w-lg">
<GlFormFieldLabel htmlFor="description">
Description
</GlFormFieldLabel>
<GlFormTextarea
defaultValue="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
id="description" />
</GlFormField>
);
}
Character count
Set characterCountLimit to display an associated counter. Supply localized remaining and over-limit text based on the current value.
Textarea with character count
73 characters remaining.
73 characters remaining.
import { useState } from "react";
import { GlFormField, GlFormFieldLabel } from "gitlab-ui-react/form-field";
import { GlFormTextarea } from "gitlab-ui-react/form-textarea";
const limit = 100;
export default function FormTextareaCharacterCountExample() {
const [value, setValue] = useState("Lorem ipsum dolor sit amet.");
const remaining = limit - value.length;
return (
<GlFormField className="max-w-lg">
<GlFormFieldLabel htmlFor="summary">
Summary
</GlFormFieldLabel>
<GlFormTextarea
characterCountLimit={limit}
characterCountOverLimitText={`${Math.abs(remaining)} characters over limit.`}
id="summary"
remainingCharacterCountText={`${Math.max(remaining, 0)} characters remaining.`}
value={value}
onValueChange={setValue} />
</GlFormField>
);
}
Accessibility
- Associate the textarea with a visible
GlFormFieldLabelusing matchinghtmlForandidvalues. - Placeholder text is not a replacement for a label.
- When character counting is enabled, provide localized count text; the component connects its polite live region through
aria-describedby. - Pair invalid state with visible feedback and retain any existing
aria-describedbyreferences. - Use
submitOnEnteronly when Ctrl+Enter or Cmd+Enter is clearly communicated as a shortcut.
API
GlFormTextarea forwards supported native textarea attributes and its ref to the <textarea> element.
| Prop | Description | Default |
|---|---|---|
value |
Controls the textarea value. | — |
defaultValue |
Sets the initial uncontrolled value. | "" |
onValueChange |
Reports formatted value changes. | — |
rows |
Sets the minimum visible row count, with a minimum of two. | 4 |
maxRows |
Enables automatic height when greater than rows. |
— |
noResize |
Prevents manual resizing. | true |
characterCountLimit |
Shows a character count for the given limit. | null |
remainingCharacterCountText |
Provides localized at-or-under-limit text. | — |
characterCountOverLimitText |
Provides localized over-limit text. | — |
state |
Sets valid, invalid, or neutral appearance. | null |
debounce |
Delays onValueChange by the given milliseconds. |
0 |
formatter |
Transforms text or cancels an update by returning false. |
— |
submitOnEnter |
Calls onSubmit on Ctrl+Enter or Cmd+Enter. |
false |