Skip to main content

Textarea

Collects multi-line text for longer form content.

import { Textarea } from "@/fragments/ui";Source

Preview

<Textarea
  label="Description"
  placeholder="Enter a description..."
/>

Installation

npx @usefragments/cli add textarea

Writes src/fragments/ui/components/Textarea plus what it imports, the globals stylesheet, and .fragments/registry-lock.json, then prints the packages to add. No account, no key.

Your own registry: publish from Fragments Cloud and add --registry org/name. Connect a workspace.

Examples

With Helper Text

Supporting text sits under the box.

<Textarea
  label="Bio"
  placeholder="Tell us about yourself..."
  helperText="Max 500 characters"
  maxLength={500}
/>

Error State

Red border, and helperText becomes the reason.

<Textarea
  label="Comments"
  placeholder="Add your comments..."
  error
  helperText="This field is required"
/>

Disabled

Dimmed and unfocusable.

<Textarea
  label="Notes"
  placeholder="Cannot edit..."
  disabled
/>

Custom Rows

rows={6} doubles the visible height before scrolling.

<Textarea
  label="Long Description"
  placeholder="Enter detailed information..."
  rows={6}
/>

Sizes

Three heights: sm, md, lg.

<div style={{ display: 'flex', flexDirection: 'column', gap: '12px', maxWidth: '400px' }}>
  <Textarea label="Small" size="sm" placeholder="Small textarea" />
  <Textarea label="Medium" size="md" placeholder="Medium textarea" />
  <Textarea label="Large" size="lg" placeholder="Large textarea" />
</div>

Fixed Height

resize="none" removes the drag handle so the box stays put.

<Textarea
  label="Notes"
  placeholder="Add notes..."
  resize="none"
/>

With Character Counter

Live count against maxLength sits below the box.

<Textarea
  label="Bio"
  placeholder="Tell us about yourself..."
  maxLength={200}
  showCharCount
/>

API

Component props
Prop
Type
Default
Description
valuestringNot setControlled value
defaultValuestringNot setDefault value for uncontrolled usage
placeholderstringNot setPlaceholder text
rowsnumber3Number of visible text rows
minRowsnumberNot setMinimum number of rows when auto-resizing
maxRowsnumberNot setMaximum number of rows when auto-resizing
resizeenumnoneverticalhorizontalbothverticalResize behavior
sizeenumsmmdlg"md"Size variant
disabledbooleanfalseDisabled state
errorbooleanfalseError state
showCharCountbooleanfalseShow character counter when maxLength is set
labelstringNot setLabel text above the textarea
helperTextstringNot setHelper text below the textarea
onChangefunctionNot setCalled when the textarea value changes
onValueChangefunctionNot setValue-first change callback alias: (value: string) => void
onBlurfunctionNot setCalled when textarea loses focus
onFocusfunctionNot setCalled when textarea receives focus
namestringNot setForm field name
maxLengthnumberNot setMaximum character length
requiredbooleanNot setRequired field
aria-labelstringNot setAccessible label for no-visible-label usage
aria-labelledbystringNot setAccessible labelled-by relationship
aria-describedbystringNot setAccessible described-by relationship
rootPropsobjectNot setHTML attributes applied to the wrapper element
classNamestringNot setWrapper class name
styleobjectNot setWrapper styles

Accessibility

  • Give every textarea a visible label
  • Put format hints in helperText, not the placeholder
  • Error text says what to fix, not just that it failed

Guidance

Use when

  • Collecting multi-line text (comments, descriptions)
  • Free-form text input that may span multiple lines
  • Message composition fields
  • Code or content editing

Avoid when

  • Single-line input (use Input)
  • Rich text editing (use rich text editor)
  • Selecting from predefined options (use Select)
  • InputalternativeUse Input for single-line text

Next steps