# Textarea

Multiline input with auto sizing and a character count.

Access: free. Category: Forms. Kind: primitive.

## When to use

- Use it when a product interface needs multiline input with auto sizing and a character count.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose form-field instead when a labeled email field with validation and help text is the actual interface need, rather than textarea.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Textarea

```sh
npx shadcn@latest add https://tidalui.com/r/textarea.json
```

Stylesheets: `components/ui/tidal.css`, `components/ui/textarea.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/textarea.css";
import{TidalTextarea}from"./components/ui/textarea";
export default()=><div className="tidal-scope"><TidalTextarea label={"Demo"}/></div>;
```

## Structured props

- `TidalTextarea.label: string`: Required label value accepted by this exported component.
- `TidalTextarea.autoGrow?: boolean | undefined` (default false): Native rows and vertical resizing remain available when false.
- `TidalTextarea.description?: string | undefined`: Optional description value accepted by this exported component.
- `TidalTextarea.error?: string | undefined`: Optional error value accepted by this exported component.
- `TidalTextarea.formatCount?: ((count: number, limit: number | undefined) => string) | undefined`: Optional format count value accepted by this exported component.
- `TidalTextarea.maxRows?: number | undefined` (default 8): Optional max rows value accepted by this exported component.
- `TidalTextarea.minRows?: number | undefined` (default 3): Optional min rows value accepted by this exported component.
- `TidalTextarea.rootClassName?: string | undefined` (default ""): Optional root class name value accepted by this exported component.
- `TidalTextarea.showCount?: boolean | undefined`: Defaults to true when maxLength is present. Counts native UTF-16 units.

## Complete usage example

[Source](https://tidalui.com/examples/textarea.tsx) | [Manifest](https://tidalui.com/examples/textarea.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
import "./components/ui/tidal.css";

import { useEffect, useLayoutEffect, useRef, useState } from "react";

import { ArrowUpRight, Check, FileText, RotateCcw } from "lucide-react";

import { TidalTextarea } from "./components/ui/textarea";

import { TidalButton } from "./components/ui/tidal-button";

import "./components/ui/textarea.css";



const tidalExampleStyles = ".tidal-scope .textarea-specimen {\n  width: 100%;\n  max-width: 780px;\n  padding: 28px;\n  background: var(--t-surface);\n  border: 1px solid var(--t-border);\n  border-radius: var(--t-radius-card);\n  box-shadow:\n    0 2px 3px #00000004,\n    0 18px 35px -30px #00000045;\n}\n.tidal-scope .textarea-specimen > h3 {\n  font-size: 29px;\n  letter-spacing: -1.1px;\n  line-height: 1.15;\n  margin: 15px 0 28px;\n  font-weight: 500;\n}\n.tidal-scope .textarea-specimen > h3 em {\n  font:\n    italic 36px/1.15 \"Instrument Serif\",\n    Georgia,\n    serif;\n  letter-spacing: -0.8px;\n}\n.tidal-scope .textarea-demo-stage {\n  padding: 7px;\n  overflow: hidden;\n  transition: height 420ms var(--t-ease-out);\n  margin: 0 -7px;\n}\n.tidal-scope .textarea-demo-content {\n  display: flow-root;\n}\n.tidal-scope .textarea-demo-workspace {\n  display: grid;\n  grid-template-columns: minmax(0, 1.12fr) minmax(0, 0.88fr);\n  gap: 28px;\n  align-items: start;\n}\n.tidal-scope .textarea-demo-workspace form {\n  min-width: 0;\n}\n.tidal-scope .textarea-demo-form-head {\n  display: flex;\n  align-items: center;\n  gap: 9px;\n  margin-bottom: 20px;\n  font-size: 11px;\n  letter-spacing: 1.5px;\n  color: var(--t-muted);\n}\n.tidal-scope .textarea-demo-form-head > span:last-child {\n  margin-left: auto;\n}\n.tidal-scope .textarea-demo-pencil {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  width: 28px;\n  height: 28px;\n  border-radius: 7px;\n  background: var(--t-ink);\n  color: var(--t-surface);\n  transform: rotate(-7deg);\n  transition: transform 320ms var(--t-ease-spring);\n}\n.tidal-scope .textarea-demo-workspace form:focus-within .textarea-demo-pencil {\n  transform: rotate(0);\n}\n.tidal-scope .textarea-demo-actions {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  margin-top: 20px;\n}\n.tidal-scope .textarea-demo-actions .tidal-button {\n  font-size: 11px;\n  padding: 0 12px;\n  flex: 1;\n}\n.tidal-scope .textarea-demo-actions > button:last-child {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  width: 44px;\n  height: 44px;\n  flex: none;\n  border: 1px solid var(--t-border);\n  background: var(--t-subtle);\n  color: var(--t-ink);\n  border-radius: 10px;\n}\n.tidal-scope .textarea-demo-actions > button:disabled {\n  opacity: 0.55;\n  cursor: not-allowed;\n}\n.tidal-scope .textarea-demo-paper {\n  position: relative;\n  min-width: 0;\n  border: 1px solid var(--t-border);\n  border-radius: 10px;\n  background: var(--t-subtle);\n  box-shadow: 0 8px 15px -10px #00000028;\n  transform: rotate(1.5deg);\n  transition:\n    transform 420ms var(--t-ease-out),\n    box-shadow 420ms;\n  animation: tidal-textarea-paper-in 600ms var(--t-ease-out) both;\n}\n.tidal-scope .textarea-demo-paper:before {\n  content: \"\";\n  position: absolute;\n  inset: 5px 4px -5px -4px;\n  border: 1px solid var(--t-border);\n  border-radius: inherit;\n  background: var(--t-surface);\n  z-index: -1;\n  transform: rotate(-2deg);\n}\n.tidal-scope .textarea-demo-workspace:focus-within .textarea-demo-paper,\n.tidal-scope .textarea-specimen[data-phase=\"saved\"] .textarea-demo-paper {\n  transform: rotate(0);\n  box-shadow: 0 12px 24px -15px #00000030;\n}\n.tidal-scope .textarea-demo-paper-top {\n  display: flex;\n  justify-content: space-between;\n  gap: 8px;\n  padding: 18px 18px 12px;\n  border-bottom: 1px solid var(--t-border);\n  font-size: 11px;\n  letter-spacing: 1.3px;\n  color: var(--t-muted);\n}\n.tidal-scope .textarea-demo-paper-body {\n  padding: 20px 18px;\n  min-height: 166px;\n  background: repeating-linear-gradient(\n    transparent,\n    transparent 23px,\n    color-mix(in srgb, var(--t-border) 35%, transparent) 23px,\n    color-mix(in srgb, var(--t-border) 35%, transparent) 24px\n  );\n  background-position: 0 20px;\n  overflow-wrap: anywhere;\n}\n.tidal-scope .textarea-demo-paper-body p {\n  font-size: 11px;\n  line-height: 24px;\n  color: var(--t-ink);\n  margin: 0 0 12px;\n  white-space: pre-wrap;\n}\n.tidal-scope .textarea-demo-paper-body p:last-child {\n  margin-bottom: 0;\n}\n.tidal-scope .textarea-demo-paper-body .textarea-demo-placeholder {\n  font-size: 19px;\n  line-height: 1.35;\n  letter-spacing: -0.45px;\n  padding-top: 17px;\n}\n.tidal-scope .textarea-demo-placeholder em {\n  font:\n    italic 26px/1.25 \"Instrument Serif\",\n    Georgia,\n    serif;\n}\n.tidal-scope .textarea-demo-paper-foot {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 10px;\n  padding: 14px 18px;\n  border-top: 1px solid var(--t-border);\n  font-size: 11px;\n  color: var(--t-muted);\n}\n.tidal-scope .textarea-demo-paper-foot strong {\n  display: inline-block;\n  min-width: 2ch;\n  color: var(--t-ink);\n  font-weight: 500;\n  font-variant-numeric: tabular-nums;\n}\n.tidal-scope .textarea-demo-paper-foot > span:last-child {\n  display: flex;\n  align-items: center;\n  gap: 5px;\n}\n.tidal-scope .textarea-demo-note {\n  font-size: 11px;\n  line-height: 1.6;\n  margin: 24px 0 0;\n  color: var(--t-muted);\n}\n.tidal-scope .textarea-demo-saved {\n  text-align: center;\n  padding: 8px 0 24px;\n  animation: tidal-textarea-paper-in 420ms var(--t-ease-out) both;\n}\n.tidal-scope .textarea-demo-check {\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  width: 44px;\n  height: 44px;\n  margin: 0 auto 18px;\n  background: var(--t-ink);\n  color: var(--t-surface);\n  border-radius: 50%;\n}\n.tidal-scope .textarea-demo-saved h4 {\n  font-size: 24px;\n  font-weight: 500;\n  letter-spacing: -0.8px;\n  margin: 0;\n  outline-offset: -5px;\n  padding: 5px;\n}\n.tidal-scope .textarea-demo-saved p {\n  font-size: 11px;\n  color: var(--t-muted);\n  margin: 10px 0 0;\n  line-height: 1.6;\n}\n.tidal-scope .textarea-specimen[data-phase=\"saved\"] .textarea-demo-workspace {\n  display: block;\n  max-width: 440px;\n  margin: auto;\n}\n.tidal-scope .textarea-specimen[data-phase=\"saved\"] .textarea-demo-paper-body {\n  min-height: 0;\n}\n.tidal-scope .textarea-demo-saved-actions {\n  display: flex;\n  justify-content: center;\n  gap: 10px;\n  margin-top: 24px;\n}\n.tidal-scope .textarea-demo-saved-actions .tidal-button {\n  font-size: 11px;\n}\n.tidal-scope .textarea-demo-actions > button:focus-visible,\n.tidal-scope .textarea-demo-saved-actions > button:focus-visible {\n  outline-offset: -5px;\n  outline-color: currentColor;\n}\n@keyframes tidal-textarea-paper-in {\n  from {\n    opacity: 0;\n    translate: 0 9px;\n  }\n  to {\n    opacity: 1;\n    translate: 0 0;\n  }\n}\n@media (max-width: 650px) {\n  .tidal-scope .textarea-specimen {\n    padding: 22px;\n  }\n  .tidal-scope .textarea-demo-workspace {\n    grid-template-columns: minmax(0, 1fr);\n    gap: 20px;\n  }\n  .tidal-scope .textarea-demo-paper-body {\n    min-height: 85px;\n    max-height: 120px;\n    overflow-y: auto;\n    padding: 14px 18px;\n  }\n  .tidal-scope .textarea-demo-paper-body .textarea-demo-placeholder {\n    padding-top: 0;\n  }\n  .tidal-scope .textarea-demo-paper-top {\n    padding-top: 12px;\n  }\n  .tidal-scope .textarea-demo-paper-foot {\n    padding-top: 10px;\n    padding-bottom: 10px;\n  }\n  .tidal-scope .textarea-demo-form-head {\n    margin-bottom: 14px;\n  }\n}\n@media (prefers-reduced-motion: reduce) {\n  .tidal-scope .textarea-demo-pencil,\n  .tidal-scope .textarea-demo-workspace form:focus-within .textarea-demo-pencil,\n  .tidal-scope .textarea-demo-paper,\n  .tidal-scope .textarea-demo-workspace:focus-within .textarea-demo-paper,\n  .tidal-scope .textarea-specimen[data-phase=\"saved\"] .textarea-demo-paper {\n    transform: none;\n  }\n}\n@media (max-width: 650px) {\n  .tidal-scope .textarea-specimen {\n    padding: 18px;\n  }\n  .tidal-scope .textarea-specimen > h3 {\n    font-size: 25px;\n    margin-top: 10px;\n    margin-bottom: 16px;\n  }\n  .tidal-scope .textarea-specimen > h3 em {\n    font-size: 32px;\n  }\n  .tidal-scope .textarea-demo-form-head {\n    display: none;\n  }\n  .tidal-scope .textarea-demo-paper-body {\n    max-height: 85px;\n  }\n  .tidal-scope .textarea-demo-note {\n    margin-top: 8px;\n  }\n}";

const sample =
  "Make the handoff feel effortless. Keep the next step clear, the details close and the interface quiet.\n\nLeave a little room for the thought that comes next.";

export function TextareaDemo() {
  const [text, setText] = useState(""),
    [error, setError] = useState("");
  const [phase, setPhase] = useState<"editing" | "saving" | "saved">("editing");
  const [height, setHeight] = useState<number>();
  const input = useRef<HTMLTextAreaElement>(null),
    title = useRef<HTMLHeadingElement>(null),
    content = useRef<HTMLDivElement>(null);
  const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined),
    restore = useRef(false);
  const focusOwner = useRef<HTMLElement | null>(null);
  const words = text.trim() ? text.trim().split(/\s+/u).length : 0;
  useEffect(() => () => clearTimeout(timer.current), []);
  useLayoutEffect(() => {
    const active = document.activeElement;
    const canMoveFocus =
      active === document.body || active === focusOwner.current;
    if (phase === "saved" && canMoveFocus) {
      title.current?.focus({ preventScroll: true });
      focusOwner.current = null;
    } else if (phase === "editing" && restore.current) {
      restore.current = false;
      if (canMoveFocus) input.current?.focus({ preventScroll: true });
      focusOwner.current = null;
    }
  }, [phase]);
  useLayoutEffect(() => {
    const node = content.current;
    if (!node) return;
    const measure = () => {
      const css = getComputedStyle(node.parentElement!);
      setHeight(
        node.offsetHeight +
          Number.parseFloat(css.paddingTop) +
          Number.parseFloat(css.paddingBottom),
      );
    };
    measure();
    const ro = new ResizeObserver(measure);
    ro.observe(node);
    return () => ro.disconnect();
  }, []);
  function edit() {
    clearTimeout(timer.current);
    focusOwner.current =
      document.activeElement instanceof HTMLElement
        ? document.activeElement
        : null;
    restore.current = true;
    setPhase("editing");
    if (phase === "editing") {
      restore.current = false;
      input.current?.focus({ preventScroll: true });
    }
  }
  function clear() {
    setText("");
    setError("");
    edit();
  }
  return (
    <div className="textarea-specimen" data-phase={phase}>
      <div className="textarea-demo-stage" style={{ height }}>
        <div ref={content} className="textarea-demo-content">
          {phase === "saved" ? (
            <div className="textarea-demo-saved">
              <span className="textarea-demo-check" aria-hidden="true">
                <Check size={22} />
              </span>
              <h4 tabIndex={-1} ref={title}>
                A thought, kept here.
              </h4>
              <p>
                This sample stays in this preview until you clear it or leave.
              </p>
            </div>
          ) : null}
          <div className="textarea-demo-workspace">
            {phase !== "saved" ? (
              <form
                noValidate
                onSubmit={(event) => {
                  event.preventDefault();
                  if (!text.trim()) {
                    setError("Write a short note before keeping the sample.");
                    input.current?.focus({ preventScroll: true });
                    return;
                  }
                  focusOwner.current =
                    (event.nativeEvent as SubmitEvent).submitter instanceof
                    HTMLElement
                      ? (event.nativeEvent as SubmitEvent).submitter
                      : document.activeElement instanceof HTMLElement
                        ? document.activeElement
                        : null;
                  setError("");
                  setPhase("saving");
                  timer.current = setTimeout(() => setPhase("saved"), 650);
                }}
              >
                <div className="textarea-demo-form-head">
                  <span className="textarea-demo-pencil" aria-hidden="true">
                    <FileText size={15} />
                  </span>
                  <span>THE DRAFT</span>
                  <span>01</span>
                </div>
                <TidalTextarea
                  ref={input}
                  label="Project note"
                  name="sample-note"
                  value={text}
                  onChange={(event) => {
                    setText(event.target.value);
                    setError("");
                  }}
                  placeholder="What should the next person know?"
                  maxLength={280}
                  autoGrow
                  minRows={3}
                  maxRows={6}
                  required
                  description="Describe the project requirements."
                  error={error}
                  disabled={phase === "saving"}
                />
                <div className="textarea-demo-actions">
                  <TidalButton
                    type="button"
                    variant="secondary"
                    onClick={() => {
                      if (phase === "saving") {
                        edit();
                        return;
                      }
                      setText(sample);
                      setError("");
                      input.current?.focus({ preventScroll: true });
                    }}
                  >
                    {phase === "saving" ? "Cancel save" : "Fill sample"}
                  </TidalButton>
                  <TidalButton type="submit" loading={phase === "saving"}>
                    Keep sample
                    <ArrowUpRight size={13} aria-hidden="true" />
                  </TidalButton>
                  <button
                    type="button"
                    aria-label="Clear note"
                    onClick={clear}
                    disabled={phase === "saving"}
                  >
                    <RotateCcw size={15} />
                  </button>
                </div>
              </form>
            ) : null}
            <aside
              className="textarea-demo-paper"
              aria-label="Live note preview"
            >
              <div className="textarea-demo-paper-top">
                <span>THE THOUGHT</span>
                <span>N / 026</span>
              </div>
              <div
                className="textarea-demo-paper-body"
                tabIndex={0}
                role="region"
                aria-label="Note preview text"
              >
                {text.trim() ? (
                  text
                    .split(/\n\s*\n/u)
                    .map((paragraph, i) => <p key={i}>{paragraph}</p>)
                ) : (
                  <p className="textarea-demo-placeholder">
                    Your note
                    <br />
                    <em>appears here.</em>
                  </p>
                )}
              </div>
              <div className="textarea-demo-paper-foot">
                <span>
                  <strong>{words}</strong> {words === 1 ? "word" : "words"}
                </span>
                <span>
                  {phase === "saved" ? (
                    <>
                      <Check size={11} /> Sample kept
                    </>
                  ) : (
                    "Live preview"
                  )}
                </span>
              </div>
            </aside>
          </div>
          {phase === "saved" ? (
            <div className="textarea-demo-saved-actions">
              <TidalButton variant="secondary" onClick={edit}>
                Edit sample
              </TidalButton>
              <TidalButton variant="ghost" onClick={clear}>
                Clear sample
              </TidalButton>
            </div>
          ) : null}
        </div>
      </div>
      <p className="textarea-demo-note">
        A local writing sample. No messages sent, uploads or storage.
      </p>
    </div>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <TextareaDemo />
    </div>
  );
}

```

## Gotchas

- Keep field state, validation results, submission, and persistence in the host form workflow.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Required visible label. Native controlled value/onChange or uncontrolled defaultValue, textarea attributes/ref/name/required/disabled/readOnly/id, keyboard, selection and composition handlers supported. Native rows(default3) and vertical resizing remain available by default. Optional autoGrow(defaultfalse) measures actual native scrollHeight; minRows(default3) and maxRows(default8) finite values floor/clamp1..50, max is at least min, and autoGrow manages rows/height/minHeight/resize. Content grows/shrinks smoothly to the row limit and then scrolls; width/font changes remeasure in untransformed client coordinates. className applies to textarea, rootClassName to wrapper; other style props are retained. Optional maxLength floors finite nonnegative limits including0; invalid limits are omitted. Native user-input limit is preserved without truncating initial or external caller values. showCount defaults to true when maxLength is present, or opts into an unlimited count. Counts use native UTF-16 string length, matching maxLength; decorative rolling digits and a limit rail never announce each keystroke. formatCount(count,limit) localizes the visible/accessible text and replaces rolling digits. Count/help/error IDs merge with caller aria-describedby; error forces aria-invalid and role=alert; externally supplied over-limit text also sets aria-invalid without mutating the value. Uncontrolled change and native form reset update count and sizing, including prevented reset. Programmatic DOM-value changes without input events are outside React state; use a controlled value or dispatch the appropriate native input event. Native IME handlers are forwarded unchanged; no submission shortcut, wrapper form, collection, persistence or network work is introduced. Reduced motion makes counts, height, rail and feedback resolve immediately. Consumers own validation, submission and storage.
