Skip to content

CdsTextArea

A text area is a field for multiline text: a comment, a description, a support request. Around the native textarea the component gathers everything a form needs: a label, a description, hints, error messages, clearing and a character counter, and with auto-grow it grows together with the text.

Storybook GitLab Figma
Test coverage: 98% — good coverage
API in specs
85 / 85 props, events, slots and exposed members with a test
Test cases
95 unit · 2 browser
Known bugs
9 pinned by an it.fails test
Code coverage
97.9% lines · 86.3% branches measured in v4.0.0-alpha.13
A11y (axe)
4 recommendations in 12 stories measured in v4.0.0-alpha.11

For a short single-line value use CdsTextInput, to pick from a ready list of options — CdsSelect.

Anatomy ​

On top are the label and the description, in the center is the multiline field with the clear button, under the field are the messages line and the character counter. The structure matches CdsTextInput: the same prepend / append zones outside and inside the border are available — as *-icon props and as slots of the same name.

Variations ​

Label and description ​

The label prop names the field, description adds a supporting text under the label. The slots of the same name accept arbitrary markup.

Number of rows ​

The rows prop sets the height of the area in rows — 5 by default. Choose the height to match the expected length of the answer: two or three rows are enough for a comment.

Automatic height ​

The auto-grow prop increases the height of the area as you type — the text does not have to be scrolled. max-rows limits the growth by a number of rows, max-height — by a height in pixels; beyond that a scrollbar appears.

Resizing ​

By default the user can stretch the area by its bottom right corner. The no-resize prop turns that off; with auto-grow manual resizing is disabled automatically.

Clearing ​

The clearable prop shows the clear icon on hover or focus, persistent-clearable keeps it visible at all times.

Counter ​

The counter prop shows a character counter: true — without a limit, a number — with a limit. counter-value accepts your own counting formula, persistent-counter keeps the counter visible outside of focus. To make the limit impossible to exceed, add the maxlength attribute.

States ​

disabled blocks the input and lowers the contrast, readonly forbids changes but keeps focus and copying, loading shows a loading indicator — as a bar or as a circle (loading="circle").

Guidelines ​

Scenarios ​

Sending a request ​

The form is made of CdsForm, a short subject in a text field and the message in a text area. The rules prop checks that the message is detailed enough, and counter together with maxlength show the limit upfront. The button gets loading for the duration of the request.

A comment in a discussion ​

A compact comment field: rows="1" and auto-grow with max-rows — the area starts with a single row and grows together with the text, hide-details removes the bottom block. The send button is a CdsFunctionalButton in the append-inner slot; Enter sends the comment, Shift+Enter inserts a line break.

An error from the server ​

The server response goes into error-messages as is — validation through rules is not needed for that. Reset the error when the value changes, so that the field does not complain about a text that is already fixed.

API ​

Props

NameTypeDefaultDescription
activeboolean | undefined—Active state of the field
activeColorstring | undefined—Color of the component in its active state
appendIconIconValue | undefined—Icon in the append slot, after the content
appendInnerIconIconValue | undefined—Icon in the inner append slot, after the content of the field
autocompletestring | undefined—Helps to influence browser suggestions. The suppress value changes the name attribute of the fields, and off relies on the browser to stop suggesting values on its own. Any other value is passed to the built-in autocomplete of the corresponding element.
autofocusboolean | undefined—Enables autofocus
autoGrowboolean | undefined—Automatic growth of the text area height as you type
baseColorstring | undefined—Color of the component in its inactive state
bgColorstring | undefined—Background color of the component
centerAffixboolean | undefined—Vertically center the appendInner, prependInner, clearIcon and label elements.
clearableboolean | undefined—Shows the clear button
clearIconIconValue | undefined'remove'Icon of the clear button
colorstring | undefined—Component color
counterstring | number | boolean | undefined—Character counter. Accepts a boolean, a number or a string
counterValuenumber | ((value: any) => number) | undefined—Custom counter value. Either a number or a function computing it from the current value
descriptionstring | undefined—Description of the component, shown under the label
dirtyboolean | undefined—Marks that the value of the field was changed by the user
disabledboolean | null | undefinednullDisabled state
errorboolean | undefined—Error state
errorMessagesstring | readonly string[] | null | undefined[]Puts the component into the error state and passes custom error messages. They are merged with any checks defined in the rules prop. This field does not trigger validation.
focusedboolean | undefined—Controls the focus state of the component. When true, the component is considered focused and may apply the corresponding styles or behavior.
hideDetailsboolean | "auto" | undefined—Hides the details block (messages and hints). With the 'auto' value the block is hidden when there are no messages
hideMessagesboolean | undefined—Hide the messages under the input
hintstring | undefined—Hint text shown under the input
iconColorstring | boolean | undefined—Icon color. Accepts a boolean or a color string
idstring | undefined—Unique identifier of the component
labelstring | undefined—Label text of the component
loadingstring | boolean | undefined—Loading indicator for the component
maxErrorsstring | number | undefined1Maximum number of validation errors shown
maxHeightstring | number | undefined—Maximum height of the text area
maxRowsstring | number | undefined—Maximum number of rows while the height grows automatically
maxWidthstring | number | undefined—Maximum component width
messagesstring | readonly string[] | undefined[]Messages shown under the input
minWidthstring | number | undefined—Minimum component width
modelModifiersRecord<string, boolean> | undefined—The v-model modifiers passed by Vue to process the field value
modelValueany—Value of the component in v-model. If the component supports the multiple prop, an empty array is used by default.
namestring | undefined—Name of the input
noResizeboolean | undefined—Turn off the ability to resize the text area
persistentClearableboolean | undefined—Always show the clear button, not only on hover or focus
persistentCounterboolean | undefined—Always show the counter, not only while the field is in use
persistentHintboolean | undefined—Always show the hint, not only on focus
persistentPlaceholderboolean | undefined—Always show the placeholder instead of hiding it while the field is in use
placeholderstring | undefined—Placeholder text shown in an empty field
prefixstring | undefined—Text prefix shown before the field value
prependIconIconValue | undefined—Icon in the prepend slot, before the content
prependInnerIconIconValue | undefined—Icon in the inner prepend slot, before the content of the field
readonlyboolean | null | undefinednullRead-only state
reverseboolean | undefined—Reverses the order of the elements inside the field
rowsstring | number | undefined5Number of rows of the text area
rulesreadonly ValidationRule[] | undefined[]Accepts an array of items of different types: functions, booleans and strings. Functions take the input value as an argument and must return either true / false, or a string with an error message. The input goes into the error state if a function returns false (or any value in the array is false) or is a string.
sizenumber | "xs" | "sm" | "md" | "lg" | "xl" | undefined'md'Size of the component
suffixstring | undefined—Text suffix shown after the field value
textColorstring | undefined—Text color of the component
themestring | undefined—Component theme
validateOnValidateOn | undefined—Changes the type of the event that triggers validation
validationValueany—Value used when applying the validation rules
widthstring | number | undefined—Component width

Events

NameTypeDescription
click:control[e: MouseEvent]Fires on a click in the main area of the control
mousedown:control[e: MouseEvent]Fires on a mouse button press in the main area of the control
update:focused[focused: boolean]Fires when the element gains or loses focus
update:modelValue[value: string]Fires when the model of the component changes
update:rows[rows: number]Fires when the computed number of rows changes while the height grows automatically

Slots

NameTypeDescription
appendCdsInputSlotAdds an element after the input
append-innerCdsInputDefaultSlotSlot added at the end of the input
clearCdsInputDefaultSlot & { props: Record<string, any>; }Slot for a custom clear icon (shown when the clearable prop is true).
counterCdsCounterSlotSlot for a custom counter
description{ description: string | undefined; props: Record<string, any>; }Default slot of the CdsDescription component
detailsCdsInputSlotSlot for custom content that lets you customize how the messages are displayed
label{ label: string | undefined; props: Record<string, any>; }Default slot of the CdsLabel component
loaderLoaderSlotPropsSlot for a custom loader (shown when the loading prop is true).
messageCdsMessageSlotSlot for customizing the content of a message
messagesCdsInputSlotSlot for custom content that lets you customize how the messages are displayed
prependCdsInputSlotAdds an element before the input
prepend-innerCdsInputDefaultSlotSlot added at the start of the input

Exposed

NameTypeDescription
controlRefHTMLElement | undefinedRef to the control of the input
fieldIconColorstring | undefinedIcon color
isDirtybooleanWhether the input is dirty
isDisabledbooleanWhether the input is disabled
isPurebooleanWhether the input is pure
isReadonlybooleanWhether the input is read-only
isValidboolean | nullWhether the input is valid
isValidatingbooleanWhether the input is being validated
reset() => Promise<void>Resets the input to its initial state
resetValidation() => Promise<void>Resets the validation of the input
validate(silent?: boolean) => Promise<string[]>Validates the input