Auto-Resize Textarea for React
A glass React textarea that auto-resizes to fit its content and can show a character counter whose ring fills as you type.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/textarea.jsonTextareadefaultTextareaLabels
Using it in a form? See the react-hook-form and zod recipe.
Auto-resize
Grows between minRows and maxRows, then scrolls. Measured off-screen, so the page never jumps while you type.
Grows from 2 up to 8 lines.
import { Textarea } from "@/components/sheenui/textarea/textarea";
// Package build (after the first npm release, or a packed tarball): import { Textarea } from "@sheenui/theme";
export function Example() {
return (
<Textarea
label="Notes"
placeholder="Write as much as you like…"
description="Grows from 2 up to 8 lines."
minRows={2}
maxRows={8}
/>
);
}Files to copy
4 folders · 6 files · 4 packages
- From
theme/src/ components/textarea/hooks/{use-controllable.ts, use-latest.ts}lib/{cn.ts, field-size.ts, form.ts, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/textarea.jsonRegistry item: textarea. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/button/components/spinner/components/toast/hooks/{use-direction.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts}motion/{gate.ts, tokens.ts}lib/state-light.tsx
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json https://lokendra-builds.github.io/sheenui/r/toast.json- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Character limit
The counter turns amber near the limit and red at it; typing past the limit is blocked with a little shake. Screen readers hear the count with the field and a polite note at 20 and 10 characters left.
import { useState } from "react";
import { Button } from "@/components/sheenui/button/button";
import { Textarea } from "@/components/sheenui/textarea/textarea";
import { useToast } from "@/components/sheenui/toast/toast";
// Package build (after the first npm release, or a packed tarball): import { Button, Textarea, useToast } from "@sheenui/theme";
import { Paperclip as PaperclipIcon, Smile as SmileIcon } from "lucide-react";
// This example also uses button, toast: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json https://lokendra-builds.github.io/sheenui/r/toast.json
export function Example() {
const [post, setPost] = useState("Shipping glass components that stay readable is mostly about contrast budgets.");
const toast = useToast();
return (
<form
className="flex w-full max-w-md flex-col items-end gap-3"
onSubmit={(e) => {
e.preventDefault();
toast.success("Posted", `${post.length} characters`);
}}
>
<Textarea
label="Post"
value={post}
onChange={(e) => setPost(e.target.value)}
maxLength={140}
minRows={2}
footer={
<>
<Button variant="ghost" size="icon" type="button" aria-label="Attach a file" className="size-8 any-pointer-coarse:size-11">
<PaperclipIcon />
</Button>
<Button variant="ghost" size="icon" type="button" aria-label="Add an emoji" className="size-8 any-pointer-coarse:size-11">
<SmileIcon />
</Button>
</>
}
/>
<Button type="submit" disabled={post.trim() === ""}>
Post
</Button>
</form>
);
}Soft limit
limit="warn" lets people keep typing and trim later: the field turns invalid and the counter shows how far over it is. This bio is a few characters short of the limit; keep typing.
Shown on your public profile.
import { useState } from "react";
import { Textarea } from "@/components/sheenui/textarea/textarea";
// Package build (after the first npm release, or a packed tarball): import { Textarea } from "@sheenui/theme";
export function Example() {
const [bio, setBio] = useState("Designer and front-end developer in Lisbon. I care about motion that helps, contrast that holds up, and calm UI.");
return (
<Textarea
label="Bio"
value={bio}
onChange={(e) => setBio(e.target.value)}
maxLength={120}
limit="warn"
error={bio.length > 120 ? "Keep your bio to 120 characters." : undefined}
description="Shown on your public profile."
/>
);
}Props
TextareaLabels keys and English defaults (4)
Keyboard
Accessibility
- label, description, error and the character count are linked with aria-labelledby and aria-describedby; an error is announced politely.
- The character count sits in a polite live region. Text is 16 px on touch screens so iOS does not zoom.
- autoResize grows the field with its content and keeps the caret and scroll position.
All exports on this page
Textarea— A glass multi-line field.defaultTextareaLabels— Default English strings of TextareaLabels; spread it and override single keys to reword.
When to use Textarea
- Use it as an auto-resize textarea for a comment box or a chat reply composer that should grow as people type, between minRows and maxRows, and then scroll instead of pushing the page down.
- Use it for a profile bio with a 280 character limit, where the counter ring turns amber near the limit and red at it, and screen readers hear the count with the field.
- Use it for a message form with actions beneath the text, since the footer prop places buttons in the bottom row left of the counter without extra layout code.
- Skip it when the answer is a single line; Input handles that, and a code or rich text editor needs a dedicated editor component rather than a styled native textarea.
- Pair it with Button in the footer slot for send or save, Rating above it for a feedback form, and the Field-style label, description and error props already built into it.
Frequently asked questions
Related pages
67 components pages in all: browse them on All components.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .