Textarea
Room to write: it grows, it counts, and it shakes on errors.
Installation
npx shadcn@latest add https://fabrickit.org/r/textarea.jsonpnpm dlx shadcn@latest add https://fabrickit.org/r/textarea.jsonyarn shadcn@latest add https://fabrickit.org/r/textarea.jsonbunx --bun shadcn@latest add https://fabrickit.org/r/textarea.jsonThis 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.
Step 1: Add the theme (once)
Every colour, radius and curve the components use, as --fabric-* variables. Save it as fabric.css next to your global CSS and import it there. If you've added another Fabric Kit component before, skip this.globals.css@import "./fabric.css";fabric.css/* * fabric.css — Fabric Kit's theme: every colour, radius, ring and curve the * components use, as --fabric-* variables (prefixed, so they never clash * with your own shadcn theme). Installed by `shadcn add @fabrickit/theme` * (it lands in your global CSS) — or import this file once, globally. * Dark by default. For light, put data-theme="light" on <html> (or on any * element: the tokens follow it down the tree; data-theme="dark" turns back). */ :root, [data-theme="dark"] { --fabric-page: #111111; --fabric-surface: #191919; /* triggers, recessed tiles */ --fabric-panel: #202020; /* open panels */ --fabric-raised: #2a2a2a; /* hover, range band */ --fabric-raised-hi: #343434; /* hover inside a band */ --fabric-preview: #252525; /* soft preview fills */ --fabric-text: #e0e0e0;Step 2: Add what it builds on
It uses Input. Add it first, the same way (skip any you already have).Step 3: Copy the shared engines
Plain JavaScript that does the motion, shared between components. Create each file at the same path in your project; if a file is already there from another component, keep it.lib/fabricui/mount.js/* * mount.js — runs a Fabric Kit engine for a React component and cleans up * after it. The engines are plain JavaScript that wire themselves to the page * (listeners on the document, resize observers, a few elements of their own); * mount() records everything an engine attaches and changes while it's being * set up, and dispose() takes it all back, so a component can come and go (or * be set up twice in a row, as React's Strict Mode does) without leaving * anything behind. * * const m = mount(() => new Engine(root, options)); * m.instance; // the engine * m.dispose(); // on unmount: listeners and observers off, the DOM as it was, then instance.destroy() * // (and destroy() on anything it owns that registered itself, like each ClothDrop) */ export function mount(create) { const ac = new AbortController();Step 4: Copy the Textarea files
The component itself. Create each one at the same path in your project. It's your code from here on.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-tapStep 5: Check the import paths
The files import each other through the @/ alias (the shadcn default, there in a new Next.js app). If your project doesn't have it, add it to tsconfig.json, or change the imports to relative paths.tsconfig.json{ "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./*"] } } }Step 6: Use it
Import it from @/components/fabricui/textarea. The Usage example below shows it in a page.
Code
"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).
*//*
* 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-tapUsage
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
| Prop | Type | Default |
|---|---|---|
| autoGrow Start one line tall and grow smoothly with what's typed, up to 160px, then scroll. | boolean | false |
| 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. | boolean | true |
| 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 | — |