On this page

Textarea

Live examples of Textarea, with the exact Vue file that renders each one.

Every example is a complete Vue file. Copy it into an app that has the registry installed, or open it in StackBlitz. The box grows as you type.

Label, help text and a limit

The help text says where the note appears and how many characters are left.

TextareaWithHelp.vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import { Field, FieldDescription, FieldLabel } from '@/components/ui/field'
import { Textarea } from '@/components/ui/textarea'

const note = ref('')
const left = computed(() => 200 - note.value.length)
</script>

<template>
  <Field class="max-w-md">
    <FieldLabel for="slip-note">Note on the packing slip</FieldLabel>
    <Textarea id="slip-note" v-model="note" maxlength="200" aria-describedby="slip-note-help" />
    <FieldDescription id="slip-note-help">Printed under the order lines. {{ left }} characters left.</FieldDescription>
  </Field>
</template>

Error

A required reason left empty. Type one and the error goes away.

TextareaInvalid.vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import { Field, FieldError, FieldLabel } from '@/components/ui/field'
import { Textarea } from '@/components/ui/textarea'

// Shown after the person tried to submit: the reason is required. Type one to clear the error.
const reason = ref('')
const invalid = computed(() => reason.value.trim().length === 0)
</script>

<template>
  <Field class="max-w-md" :data-invalid="invalid">
    <FieldLabel for="refund-reason">Reason for the refund</FieldLabel>
    <Textarea
      id="refund-reason"
      v-model="reason"
      :aria-invalid="invalid"
      :aria-describedby="invalid ? 'refund-reason-error' : undefined"
    />
    <FieldError v-if="invalid" id="refund-reason-error">Enter a reason. The customer sees it in the refund email.</FieldError>
  </Field>
</template>