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
| Name | Type | Default | Description |
|---|---|---|---|
active | boolean | undefined | — | Active state of the field |
activeColor | string | undefined | — | Color of the component in its active state |
appendIcon | IconValue | undefined | — | Icon in the append slot, after the content |
appendInnerIcon | IconValue | undefined | — | Icon in the inner append slot, after the content of the field |
autocomplete | string | 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. |
autofocus | boolean | undefined | — | Enables autofocus |
autoGrow | boolean | undefined | — | Automatic growth of the text area height as you type |
baseColor | string | undefined | — | Color of the component in its inactive state |
bgColor | string | undefined | — | Background color of the component |
centerAffix | boolean | undefined | — | Vertically center the appendInner, prependInner, clearIcon and label elements. |
clearable | boolean | undefined | — | Shows the clear button |
clearIcon | IconValue | undefined | 'remove' | Icon of the clear button |
color | string | undefined | — | Component color |
counter | string | number | boolean | undefined | — | Character counter. Accepts a boolean, a number or a string |
counterValue | number | ((value: any) => number) | undefined | — | Custom counter value. Either a number or a function computing it from the current value |
description | string | undefined | — | Description of the component, shown under the label |
dirty | boolean | undefined | — | Marks that the value of the field was changed by the user |
disabled | boolean | null | undefined | null | Disabled state |
error | boolean | undefined | — | Error state |
errorMessages | string | 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. |
focused | boolean | undefined | — | Controls the focus state of the component. When true, the component is considered focused and may apply the corresponding styles or behavior. |
hideDetails | boolean | "auto" | undefined | — | Hides the details block (messages and hints). With the 'auto' value the block is hidden when there are no messages |
hideMessages | boolean | undefined | — | Hide the messages under the input |
hint | string | undefined | — | Hint text shown under the input |
iconColor | string | boolean | undefined | — | Icon color. Accepts a boolean or a color string |
id | string | undefined | — | Unique identifier of the component |
label | string | undefined | — | Label text of the component |
loading | string | boolean | undefined | — | Loading indicator for the component |
maxErrors | string | number | undefined | 1 | Maximum number of validation errors shown |
maxHeight | string | number | undefined | — | Maximum height of the text area |
maxRows | string | number | undefined | — | Maximum number of rows while the height grows automatically |
maxWidth | string | number | undefined | — | Maximum component width |
messages | string | readonly string[] | undefined | [] | Messages shown under the input |
minWidth | string | number | undefined | — | Minimum component width |
modelModifiers | Record<string, boolean> | undefined | — | The v-model modifiers passed by Vue to process the field value |
modelValue | any | — | Value of the component in v-model. If the component supports the multiple prop, an empty array is used by default. |
name | string | undefined | — | Name of the input |
noResize | boolean | undefined | — | Turn off the ability to resize the text area |
persistentClearable | boolean | undefined | — | Always show the clear button, not only on hover or focus |
persistentCounter | boolean | undefined | — | Always show the counter, not only while the field is in use |
persistentHint | boolean | undefined | — | Always show the hint, not only on focus |
persistentPlaceholder | boolean | undefined | — | Always show the placeholder instead of hiding it while the field is in use |
placeholder | string | undefined | — | Placeholder text shown in an empty field |
prefix | string | undefined | — | Text prefix shown before the field value |
prependIcon | IconValue | undefined | — | Icon in the prepend slot, before the content |
prependInnerIcon | IconValue | undefined | — | Icon in the inner prepend slot, before the content of the field |
readonly | boolean | null | undefined | null | Read-only state |
reverse | boolean | undefined | — | Reverses the order of the elements inside the field |
rows | string | number | undefined | 5 | Number of rows of the text area |
rules | readonly 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. |
size | number | "xs" | "sm" | "md" | "lg" | "xl" | undefined | 'md' | Size of the component |
suffix | string | undefined | — | Text suffix shown after the field value |
textColor | string | undefined | — | Text color of the component |
theme | string | undefined | — | Component theme |
validateOn | ValidateOn | undefined | — | Changes the type of the event that triggers validation |
validationValue | any | — | Value used when applying the validation rules |
width | string | number | undefined | — | Component width |
Events
| Name | Type | Description |
|---|---|---|
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
| Name | Type | Description |
|---|---|---|
append | CdsInputSlot | Adds an element after the input |
append-inner | CdsInputDefaultSlot | Slot added at the end of the input |
clear | CdsInputDefaultSlot & { props: Record<string, any>; } | Slot for a custom clear icon (shown when the clearable prop is true). |
counter | CdsCounterSlot | Slot for a custom counter |
description | { description: string | undefined; props: Record<string, any>; } | Default slot of the CdsDescription component |
details | CdsInputSlot | Slot 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 |
loader | LoaderSlotProps | Slot for a custom loader (shown when the loading prop is true). |
message | CdsMessageSlot | Slot for customizing the content of a message |
messages | CdsInputSlot | Slot for custom content that lets you customize how the messages are displayed |
prepend | CdsInputSlot | Adds an element before the input |
prepend-inner | CdsInputDefaultSlot | Slot added at the start of the input |
Exposed
| Name | Type | Description |
|---|---|---|
controlRef | HTMLElement | undefined | Ref to the control of the input |
fieldIconColor | string | undefined | Icon color |
isDirty | boolean | Whether the input is dirty |
isDisabled | boolean | Whether the input is disabled |
isPure | boolean | Whether the input is pure |
isReadonly | boolean | Whether the input is read-only |
isValid | boolean | null | Whether the input is valid |
isValidating | boolean | Whether 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 |