Skip to content
English

How it works

Looks like the text input (fill, hairline, hover, growing focus halo, error tint, disabled), with a native <textarea> inside. A single row is exactly as tall as the same-size input. Auto-grow collapses the height to read scrollHeight, clamps it between the minimum and maximum rows, and slides to the new height, even continuing from halfway. The count has its own line inside the box, and IME composition does not make it jump.

Use it for

  • Notes, descriptions, comments, reviews and rejection reasons: anything written as a paragraph.
  • Content that varies a lot in length: turn on autoSize and set maxRows so the page does not stretch.
  • A length limit: set maxLength together with showCount so people see how much is left.

Look elsewhere when

  • One-line values such as names, titles and phone numbers: use a text input.
  • Content that needs bold, images or layout: use a rich text editor.
  • Chat boxes where Enter sends: Enter inserts a new line here, so wire sending to onKeyDown yourself.

Usage

import { useState } from 'react'
import { Textarea } from './Textarea.jsx'

export function ReviewField() {
  const [review, setReview] = useState('')
  return (
    <>
      <label htmlFor="review">Review</label>
      <Textarea
        id="review"
        value={review}
        onChange={setReview}
        autoSize={{ minRows: 2, maxRows: 6 }}
        showCount
        maxLength={200}
        placeholder="For example: comfortable fit, battery lasts a week"
      />
    </>
  )
}

// Fixed 4 rows, scrolling inside when there is more: <Textarea rows={4} />

Props

PropTypeDefaultWhat it does
valuestring—Controlled value; leave it out for uncontrolled use.
defaultValuestring—Initial value when uncontrolled.
onChange(value, event) => void—Called on change: the first argument is the string value, the second the native event.
size'sm' | 'md' | 'lg''md'Font 14 / 15 / 16px, line height 20 / 22 / 24px, corners 10 / 12 / 14px; one row is 36 / 44 / 52px tall like the text input. Use lg on mobile.
rowsnumber3Visible rows when autoSize is off; more content scrolls inside.
autoSizeboolean | { minRows?, maxRows? }falseHeight follows the content: true grows from rows without limit; an object sets the minimum and maximum rows, and beyond the maximum it scrolls inside.
resize'none' | 'vertical''none'Whether users can drag the corner to change the height. The width can never be dragged. Ignored with autoSize.
maxLengthnumber—Maximum characters (native maxLength; extra input is rejected).
showCountbooleanfalseShows the count at the bottom right inside the box, as “typed / limit” when maxLength is set.
labelsobject—Replaces the text read out for the count (count: (n) => string, countOf: (n, max) => string). Shallow-merged over the English defaults.
invalidbooleanfalseError state: danger hairline and a faint danger tint, plus aria-invalid="true". Place the message under the box and link it with aria-describedby.
disabledbooleanfalseDisabled: the fill stays, the hairline goes, text is muted and it cannot be focused.
refRef<HTMLTextAreaElement>—Forwarded to the native <textarea>, so it works with react-hook-form's register.
...restTextareaHTMLAttributes—className and style go to the outer element; other native attributes (id, name, placeholder, readOnly, onBlur) go to the <textarea>.

Accessibility

  • It is a native <textarea>; link the label with <label htmlFor>.
  • invalid sets aria-invalid="true"; link the message with aria-describedby.
  • The count is linked through aria-describedby and read as “36 characters entered, maximum 120” rather than character by character; replace the wording with labels.
  • Count text keeps at least 4.5:1 contrast and turns danger red over the limit.
  • On touch devices a single row is still at least 44px tall; with reduced motion the height changes without a transition.

Motion

Growing and shrinking: height 240ms ease-out, able to continue from halfway. On focus the fill turns white in 160ms and the accent line and halo grow in over 220ms.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

Textarea.jsxtextarea.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Form inputs
Availability grid comes with Pro. Its preview shows once you unlock it.
Boolean operations comes with Pro. Its preview shows once you unlock it.
Cascader comes with Pro. Its preview shows once you unlock it.