Keyboard shortcut: Ctrl + K
Get started

Textarea

VTextarea is a multiline field with optional label, help text, icons and actions. Use autoGrow to fit its height to the content.

Usage

vue
<script setup lang="ts">
import { ref } from 'vue'
import { VTextarea } from 'vectis-ui'

const message = ref('')
</script>

<template>
  <VTextarea v-model="message" label="Message" placeholder="What would you like to tell us?" />
</template>

Examples

Label and hint

label names the field. hint adds help text linked through aria-describedby.

vue

Two or three sentences. It appears on your public profile.

<script setup lang="ts">
import { ref } from 'vue'
import { VTextarea } from 'vectis-ui'

const bio = ref('')
</script>

<template>
  <VTextarea
    v-model="bio"
    label="Short bio"
    hint="Two or three sentences. It appears on your public profile."
    placeholder="What do you work on?"
  />
</template>

Sizes

size adjusts padding, text and icons. rows sets the line count.

vue
<script setup lang="ts">
import { VTextarea } from 'vectis-ui'

const sizes = ['sm', 'md', 'lg'] as const
</script>

<template>
  <div class="grid">
    <VTextarea v-for="size in sizes" :key="size" :size="size" :label="size" :rows="2" />
  </div>
</template>

<style scoped>
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: var(--vectis-space-4);
}
</style>

Icons

iconStart and iconEnd align with the first line. Use #start and #end for custom content.

vue
<script setup lang="ts">
import { VTextarea } from 'vectis-ui'
import { description, info } from 'vectis-ui/icons'
</script>

<template>
  <VTextarea :icon-start="description" label="Start icon" :rows="2" />
  <VTextarea :icon-end="info" label="End icon" :rows="2" />
  <VTextarea :icon-start="description" :icon-end="info" label="Both" :rows="2" />
</template>

Clickable icons

Attach @click:icon-start or @click:icon-end to make an icon a button. Provide its accessible name with iconStartLabel or iconEndLabel.

vue

Nothing attached yet.

<script setup lang="ts">
import { computed, ref } from 'vue'
import { VTextarea } from 'vectis-ui'
import { attach_file as attachFile, code } from 'vectis-ui/icons'

const message = ref('')
const attachments = ref(0)

const hint = computed(() => {
  if (attachments.value === 0) return 'Nothing attached yet.'
  return attachments.value === 1 ? '1 file attached.' : `${attachments.value} files attached.`
})

function insertCodeBlock() {
  message.value += '\n```\n\n```'
}
</script>

<template>
  <VTextarea
    v-model="message"
    label="Message"
    :hint="hint"
    :rows="4"
    :icon-start="code"
    icon-start-label="Insert a code block"
    :icon-end="attachFile"
    icon-end-label="Attach a file"
    @click:icon-start="insertCodeBlock"
    @click:icon-end="attachments += 1"
  />
</template>

Clear button

clearable adds a button that empties the field, emits clear and restores focus.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { VTextarea } from 'vectis-ui'

const draft = ref('A first attempt, worth throwing away in one go.')
</script>

<template>
  <VTextarea v-model="draft" label="Draft" clearable :rows="3" />
</template>

Character counter

counter displays the character count below the field. With maxlength, softLimit allows typing past the limit and reports a native validation error.

vue

The browser refuses the eighty-first character.

22/80

Type past eighty and the field goes into error instead.

0/80

No limit, so the counter only counts.

0
<script setup lang="ts">
import { ref } from 'vue'
import { VTextarea } from 'vectis-ui'

const summary = ref('Vue developer in Lyon.')
const review = ref('')
const note = ref('')
</script>

<template>
  <VTextarea
    v-model="summary"
    label="Summary"
    hint="The browser refuses the eighty-first character."
    :maxlength="80"
    counter
    :rows="2"
  />

  <VTextarea
    v-model="review"
    label="Review"
    hint="Type past eighty and the field goes into error instead."
    :maxlength="80"
    soft-limit
    counter
    :rows="3"
  />

  <VTextarea
    v-model="note"
    label="Note"
    hint="No limit, so the counter only counts."
    counter
    :rows="2"
  />
</template>

Automatic height

autoGrow adjusts the height to the content, with rows as the minimum. Without it, the field scrolls and can be resized vertically.

vue
<script setup lang="ts">
import { ref } from 'vue'
import { VTextarea } from 'vectis-ui'

const text =
  'Both fields start two rows tall.\nAdd a line to each of them.\nThe first one scrolls, the second one gets taller.'

const fixed = ref(text)
const growing = ref(text)
</script>

<template>
  <VTextarea v-model="fixed" label="Fixed height" :rows="2" />
  <VTextarea v-model="growing" label="Grows with the text" :rows="2" auto-grow />
</template>

States

disabled blocks interaction. readonly allows focus and copying. invalid marks an error, and error also shows its message in place of the hint. loading shows a spinner while leaving the field editable.

vue

Say a little more than that.

Loading…
<script setup lang="ts">
import { ref } from 'vue'
import { VTextarea } from 'vectis-ui'

const invalid = ref('Too short')
const disabled = ref('Waiting on the form to be submitted')
const readonly = ref('Signed off on 12 March, and no longer open to changes')
const loading = ref('Writing a summary')
</script>

<template>
  <VTextarea
    v-model="invalid"
    label="Invalid"
    hint="Say a little more than that."
    invalid
    :rows="2"
  />
  <VTextarea v-model="disabled" label="Disabled" disabled :rows="2" />
  <VTextarea v-model="readonly" label="Read only" readonly :rows="2" />
  <VTextarea v-model="loading" label="Loading" loading :rows="2" />
</template>

API

Props

PropTypeDefault
sizeTextareaSize'sm' | 'md' | 'lg''md'
Adjusts padding, text and icons. Use rows to set the line count.
rowsnumber5
Visible line count, rounded to an integer of at least 1. With autoGrow, sets the minimum height.
autoGrowbooleanfalse
Fits the height to the content using CSS field-sizing. Disables manual resizing. Without browser support, the field keeps its fixed height and scrolls.
invalidbooleanfalse
Sets aria-invalid and the error style. Does not block form submission by itself.
disabledbooleanfalse
Disables the field, removing it from Tab navigation and form submission.
readonlybooleanfalse
Prevents editing while allowing focus and copying. Hides the clear button unless clearVisible overrides it.
labelstringnone
Visible label linked to the textarea. When omitted, provide aria-label or aria-labelledby.
hintstringnone
Help text below the field, linked through aria-describedby.
errorstringnone
Error message shown in place of the hint. Sets aria-invalid, is linked through aria-describedby and is announced when it appears.
requiredbooleanfalse
Adds an asterisk after the label and passes required to the field.
hideLabelbooleanfalse
Hides the label visually while keeping it as the accessible name.
labelPositionFieldLabelPosition'top' | 'start''top'
Places the label above the field or beside it.
iconStartIconSourcenone
Start icon. Becomes a button with @click:icon-start; then requires iconStartLabel.
iconEndIconSourcenone
End icon. Becomes a button with @click:icon-end; then requires iconEndLabel. Replaced by #end or the loading spinner.
iconStartLabelstringnone
Accessible name of the start icon button.
iconEndLabelstringnone
Accessible name of the end icon button.
loadingbooleanfalse
Replaces the end icon or #end content with a spinner. Does not disable the field.
loadingTextstringnone
Accessible spinner text. Defaults to the library dictionary.
clearablebooleanfalse
Adds a clear button when the field is non-empty and editable, unless clearVisible overrides visibility. Hidden when disabled.
clearVisiblebooleannone
Overrides the content and read-only checks for clear-button visibility. Requires clearable and an enabled field.
clearLabelstringnone
Accessible name of the clear button. Defaults to the library dictionary.
maxlengthnumbernone
Native character limit. Not applied as a native attribute with softLimit.
softLimitbooleanfalse
Allows exceeding maxlength and sets a native validation error until the value is within the limit.
counterbooleanfalse
Character count below the field: 12/80 with a limit, or 12 without one.
v-modelstring''
Field text. Defaults to an empty string.

Events

EventType
click:icon-start[event: MouseEvent]
Emitted when the start icon button is activated. Receives a MouseEvent.
click:icon-end[event: MouseEvent]
Emitted when the end icon button is activated. Receives a MouseEvent.
clear[]
Emitted after the clear button resets the value to an empty string.

Slots

SlotType
start{}
Content after iconStart. Does not replace the icon.
end{}
Content replacing iconEnd. Hidden while loading.
value-end{}
Content after the textarea, before the clear button and end icon.

Types

Types used in the API tables. Import exported types from vectis-ui.

export interface BuiltinIcon {
  name: string
  paths: readonly [string] | readonly [string, string]
}
export type IconRender =
  | { path: string; viewBox?: string }
  | { component: Component; props?: Record<string, unknown> }
  | { src: string }
  | { text: string; class?: string }
  | { class: string }
export type IconSource = string | BuiltinIcon | IconRender