Skip to content

Textarea

The Textarea component provides a flexible multi-line text input with advanced features like auto-resize functionality, character counting, and customizable resize controls.

Basic Usage

With Label and Description

Please provide detailed information

Sizes

Intent Variants

Auto-Resize

This textarea will automatically adjust its height as you type

Character Count

0 /200

Resize Controls

Disabled and Readonly States

Error State

Advanced Example

Provide a detailed description of your project

0 /500

Accessibility

The Textarea component follows WCAG 2.1 AA guidelines:

  • Keyboard Navigation: Full keyboard support for all interactions
  • Screen Reader Support: Proper labeling and descriptions
  • Focus Management: Clear focus indicators and logical tab order
  • Error Handling: Accessible error messages with aria-invalid
  • Required Fields: Clear indication of required fields
  • Character Count: Accessible character count updates

Properties

PropertyTypeDefaultDescription
placeholderstringundefinedPlaceholder text
valuestring""Current value
disabledbooleanfalseWhether the textarea is disabled
readonlybooleanfalseWhether the textarea is readonly
requiredbooleanfalseWhether the textarea is required
rowsnumber4Number of visible text lines
colsnumberundefinedNumber of visible character widths
maxLengthnumberundefinedMaximum number of characters allowed
minLengthnumberundefinedMinimum number of characters required
autoResizebooleanfalseEnable auto-resize functionality
resize"none" | "vertical" | "horizontal" | "both""vertical"Resize control options
size"small" | "medium" | "large""medium"Size of the textarea
intent"default" | "primary" | "success" | "warning" | "danger""default"Visual style variant
labelstringundefinedLabel text
descriptionstringundefinedHelper text
errorstringundefinedError message
showCharacterCountbooleanfalseShow character count display
classstringundefinedAdditional CSS classes
namestringundefinedName attribute for form submission

Features

Auto-Resize

When autoResize is enabled, the textarea automatically adjusts its height based on content:

  • Grows as content is added
  • Shrinks when content is removed
  • Maintains minimum height based on rows attribute
  • Handles paste events and window resizing

Character Count

When showCharacterCount is enabled with maxLength:

  • Displays current character count
  • Shows warning colors when approaching limit (75% = yellow, 90% = red)
  • Updates in real-time as user types
  • Provides accessible feedback for screen readers

Resize Controls

Fine-tune user resize capabilities:

  • none: Prevents manual resizing
  • vertical: Allows vertical resizing only (default)
  • horizontal: Allows horizontal resizing only
  • both: Allows resizing in both directions

Examples

Contact Form

---
import Textarea from '@uicg/cli/components/Textarea/textarea.astro'
---
<form>
<Textarea
name="message"
label="Your Message"
description="Please provide details about your inquiry"
placeholder="Tell us how we can help you..."
required={true}
autoResize={true}
maxLength={1000}
showCharacterCount={true}
rows={4}
/>
</form>

Feedback Form

<Textarea
name="feedback"
label="Feedback"
description="Share your thoughts and suggestions"
placeholder="What did you think of our service?"
autoResize={true}
resize="none"
rows={3}
/>

Code Input

<Textarea
name="code"
label="Code Snippet"
placeholder="Paste your code here..."
resize="both"
rows={10}
cols={60}
style="font-family: 'Courier New', monospace;"
/>