Textarea

Displays a form textarea or a component that looks like a textarea.

Component Features

  • 📏 Multiple Sizes: Supports xs, sm, md, lg, xl, 2xl, default size specs.
  • 📐 Auto Height: Supports autoSize prop to automatically adjust height based on content.
  • Clearable: Supports displaying a clear button.
  • ⚠️ Error State: Supports error prop to display error state.
  • 📝 Character Count: Supports showCount and maxlength props for character counting.
  • 🔄 Resize Control: Supports resize prop controlling resize behavior (none/vertical/horizontal/both).
  • 📝 Readonly & Disabled: Supports readonly and disabled props.
  • 🎨 Theme Customization: Based on BrConfigProvider for global theming and TailwindCSS local overrides.

Basic

<script setup>
import { ref } from 'vue'
const text = ref('')
</script>

<template>
  <div class="space-y-2">
    <BrTextarea v-model="text" placeholder="Type your message here." />
    <p class="text-xs text-muted-foreground">Value: {{ text }}</p>
  </div>
</template>

Auto Height

Automatically adjusts its height based on the content.

<script setup>
import { ref } from 'vue'
const message = ref('')
</script>

<template>
  <div class="space-y-2">
    <BrTextarea 
      v-model="message" 
      placeholder="Type many lines to see auto resize..." 
      auto-size 
    />
  </div>
</template>

Disabled

<template>
<div class="space-y-2">
  <BrTextarea disabled placeholder="Disabled Textarea" />
</div>
</template>

With Label

<template>
<div class="grid w-full gap-1.5">
  <BrLabel for="message-2">Your Message</BrLabel>
  <BrTextarea id="message-2" placeholder="Type your message here." />
  <p class="text-sm text-muted-foreground">
    Your message will be copied to the support team.
  </p>
</div>
</template>

With Character Count

<script setup>
import { ref } from 'vue'
const bio = ref('I am a software engineer based in San Francisco. I love building things for the web.')
</script>

<template>
  <div class="space-y-2">
    <BrLabel for="bio">Bio</BrLabel>
    <BrTextarea 
      id="bio" 
      v-model="bio" 
      placeholder="Tell us about yourself." 
      :maxlength="100" 
      show-count 
    />
  </div>
</template>

With Clear Button

<template>
<div class="space-y-2">
  <BrTextarea placeholder="Type to see clear button" clearable />
</div>
</template>

Error State

<template>
<div class="grid w-full gap-1.5">
  <BrLabel for="message-error">Error State</BrLabel>
  <BrTextarea id="message-error" placeholder="Type here..." error />
  <p class="text-sm text-destructive">
    Please enter a valid message.
  </p>
</div>
</template>

Sizes

<script setup>
import { BrTextarea, BrLabel } from '@breezeui/vue'
</script>

<template>
  <div class="grid w-full gap-4">
    <div class="grid w-full gap-1.5">
      <BrLabel>Extra Small (xs)</BrLabel>
      <BrTextarea placeholder="Type your message here." size="xs" />
    </div>
    <div class="grid w-full gap-1.5">
      <BrLabel>Small (sm)</BrLabel>
      <BrTextarea placeholder="Type your message here." size="sm" />
    </div>
    <div class="grid w-full gap-1.5">
      <BrLabel>Default</BrLabel>
      <BrTextarea placeholder="Type your message here." />
    </div>
    <div class="grid w-full gap-1.5">
      <BrLabel>Medium (md)</BrLabel>
      <BrTextarea placeholder="Type your message here." size="md" />
    </div>
    <div class="grid w-full gap-1.5">
      <BrLabel>Large (lg)</BrLabel>
      <BrTextarea placeholder="Type your message here." size="lg" />
    </div>
    <div class="grid w-full gap-1.5">
      <BrLabel>Extra Large (xl)</BrLabel>
      <BrTextarea placeholder="Type your message here." size="xl" />
    </div>
    <div class="grid w-full gap-1.5">
      <BrLabel>2X Large (2xl)</BrLabel>
      <BrTextarea placeholder="Type your message here." size="2xl" />
    </div>
  </div>
</template>

Resize Behavior

You can control the resize behavior using the resize prop.

<template>
<div class="grid w-full gap-4">
  <div class="grid w-full gap-1.5">
    <BrLabel>No Resize (none)</BrLabel>
    <BrTextarea placeholder="Cannot resize" resize="none" />
  </div>
  <div class="grid w-full gap-1.5">
    <BrLabel>Vertical (Default)</BrLabel>
    <BrTextarea placeholder="Resize vertically" resize="vertical" />
  </div>
  <div class="grid w-full gap-1.5">
    <BrLabel>Horizontal</BrLabel>
    <BrTextarea placeholder="Resize horizontally" resize="horizontal" />
  </div>
</div>
</template>

Theming

You can customize the appearance of the textarea using Tailwind CSS classes or by overriding the CSS variables in your global CSS.

Global Theme Configuration

The BrTextarea component respects the global theme configuration provided by BrConfigProvider.


<template>
  <BrConfigProvider :theme="theme">
    <BrTextarea placeholder="Themed Textarea" />
  </BrConfigProvider>
</template>

Tailwind Customization

You can also use class prop to add custom styles:

<BrTextarea class="border-purple-500 focus-visible:ring-purple-500 min-h-[150px]" />

API

Props

PropTypeDefaultDescription
modelValuestring | number-The value of the textarea.
defaultValuestring | number-The default value of the textarea.
disabledbooleanfalseWhether the textarea is disabled.
readonlybooleanfalseWhether the textarea is read-only.
placeholderstring-Placeholder text.
sizedefault | xs | sm | md | lg | xl | 2xldefaultThe size of the textarea.
errorbooleanfalseWhether to show error state.
clearablebooleanfalseWhether to show a clear button when input has value.
autoSizeboolean | objectfalseWhether to automatically adjust height.
rowsnumber | string3The visible number of lines.
maxlengthnumber | string-The maximum number of characters allowed.
showCountbooleanfalseWhether to show character count (requires maxlength).
resizenone | vertical | horizontal | bothverticalThe resize behavior.

Events

NamePayloadDescription
update:modelValuestring | numberEmitted when textarea value changes.
clear-Emitted when the clear button is clicked.
inputEventEmitted when the textarea value changes.
changeEventEmitted when the textarea value changes (on blur).
focusEventEmitted when the textarea is focused.
blurEventEmitted when the textarea is blurred.