Textarea

Room to write: it grows, it counts, and it shakes on errors.

Shown on your profile.
Try sending it as it is.

Installation

Terminal
npx shadcn@latest add https://fabrickit.org/r/textarea.json

This copies the component into components/fabricui and its engine into lib/fabricui. It's your code from then on. First time? Add the theme once: see Installation.

Code

components/fabricui/textarea.tsx
"use client";

import * as React from "react";
import { mount } from "@/lib/fabricui/mount";
import { TextareaGrip } from "@/lib/fabricui/textarea-grip";
// the shared field's styles (Input's): the box, the label, hint and error
import "./input.css";

const cx = (...c: (string | false | undefined)[]) => c.filter(Boolean).join(" ");

const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;

/**
 * Auto-grow: on each change the box eases from its current height to the
 * height its text needs (up to its max-height, then it scrolls).
 */
lib/fabricui/textarea-grip.js
/*
 * textarea-grip.js — the corner grip that resizes a Textarea.
 *
 * Drag it and the box's height follows the pointer 1:1. Past the box's
 * min/max height it gives like rubber, and springs back when let go.
 * A double-tap (or double-click) springs it back to the height it started at.
 *
 * The grip's three dots are goo (a small blur + alpha threshold, like
 * goo.js): grabbing pinches them into one drop, dragging stretches the drop
 * out behind the corner (each dot lags on its own spring), and letting go
 * pops it back into three dots with a little wobble.
 */

const MIN = 60, MAX = 360;       // the box's height range when its CSS doesn't set min-/max-height
const RUBBER = [20, 48];         // how far past the min / the max the box can be pushed (it never quite gets there)
const DOUBLE_TAP = 350;          // ms between two still presses that count as a double-tap

Usage

Usage
import { Field, FieldLabel, FieldHint } from "@/components/fabricui/input";
import { Textarea, FieldFoot, FieldCount } from "@/components/fabricui/textarea";

export function Bio() {
  return (
    <Field>
      <FieldLabel>Bio</FieldLabel>
      <Textarea max={160} aria-describedby="bio-count" />
      <FieldFoot>
        <FieldHint>Shown on your profile.</FieldHint>
        <FieldCount id="bio-count" />
      </FieldFoot>
    </Field>
  );
}

Props

PropTypeDefault
autoGrow

Start one line tall and grow smoothly with what's typed, up to 160px, then scroll.

booleanfalse
max

Count characters against this limit into the FieldCount its aria-describedby points at: brighter in the last 10%, red (and aria-invalid) past it.

number—
resizable

A corner grip to drag the box taller or shorter (60–360px, or the box's min-/max-height). Its dots pinch into a goo drop when grabbed and stretch as it moves; double-tap it to spring back. Off with autoGrow.

booleantrue
value / defaultValue

The text, controlled or not. Takes every other <textarea> prop too.

string—
FieldFoot

A row under the box: the hint on the left, a FieldCount on the right.

component—
FieldCount

Where a Textarea with max writes its count. Give it an id and point the Textarea's aria-describedby at it.

component—