Ir al contenido
Español

Cómo funciona

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.

Úsalo para

  • 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.

Busca otra opción cuando

  • 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.

Uso

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} />

Propiedades

PropiedadTipoPor defectoQué hace
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>.

Accesibilidad

  • 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.

Movimiento

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.

Añádelo a tu proyecto

Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.

Textarea.jsxtextarea.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Formularios
Cuadrícula de disponibilidad viene con Pro. La vista previa aparece al desbloquearlo.
Operaciones booleanas viene con Pro. La vista previa aparece al desbloquearlo.
Selector en cascada viene con Pro. La vista previa aparece al desbloquearlo.