Textarea
Multi-line text field with the same finish as the input, resizable vertically or growing with its content.
pnpm dlx shadcn@latest add @haze/textarea---
import { cn } from "../../../lib/haze/utils";
interface Props {
id: string;
name?: string;
rows?: number;
placeholder?: string;
/** Grows the box with its content, up to 15 rem, where the browser supports field-sizing. Turns off manual resizing. */
autoGrow?: boolean;
required?: boolean;
class?: string;
/** Any other textarea attribute, for example disabled, maxlength, aria-describedby or aria-invalid. */
[key: string]: unknown;
}
const { id, name = id, rows = 4, placeholder, required, autoGrow = false, class: className, ...rest } = Astro.props;
---
<textarea
id={id}
name={name}
rows={rows}
placeholder={placeholder}
required={required}
class={cn(
"min-h-20 w-full min-w-0 rounded-lg border border-frame-input bg-field px-3 py-2.5 text-sm/6 tracking-[-0.01em] text-foreground placeholder:text-muted-foreground",
"transition-[border-color,background-color,box-shadow] duration-150 ease-snappy hover:border-frame-foreground",
"focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/24 focus-visible:outline-hidden",
"disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-50 disabled:hover:border-frame-input aria-invalid:border-destructive! aria-invalid:focus-visible:ring-destructive/24",
autoGrow ? "max-h-60 resize-none field-sizing-content" : "resize-y",
className,
)}
{...rest}></textarea>When to use
- Messages, comments, bios and release notes that run past one line
- Contact forms where the user explains a problem in their own words
When not to use
- Short single-line values such as an email; use input
- Rich text with formatting, which needs an editor
Installation
Add the Haze registry to components.json once, then install Textarea with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/textareanpx shadcn@latest add @haze/textareayarn dlx shadcn@latest add @haze/textareabunx --bun shadcn@latest add @haze/textareaFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Element id; reference it from a label or Field. |
| name | string | id | Form field name. |
| rows | number | 4 | Visible lines before the user resizes it. |
| placeholder | string | – | Example text shown while empty. |
| autoGrow | boolean | false | Grows the box with its content up to 15 rem where the browser supports field-sizing, and turns off manual resizing. |
| required | boolean | – | Marks the field required. |
| class | string | – | Extra classes. |
| ...rest | attributes | – | Any other textarea attribute: disabled, maxlength, aria-invalid, aria-describedby. |
Keyboard interactions
- Enter
- Inserts a new line instead of submitting the form
- Tab
- Moves focus out of the field
Accessibility
- With autoGrow the box has no resize handle and stops growing at 15 rem, then scrolls; browsers without field-sizing keep the fixed rows height.
- Resizing is limited to the vertical axis so a dragged box cannot push the form past a 320 px viewport.
- The component renders no label; pair it with Field or a label whose for matches the id.
- aria-invalid turns the border destructive, but also add an error message so the state is not shown by color alone.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Textarea" with `npx shadcn@latest add @haze/textarea`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import Textarea from "@/components/haze/ui/textarea.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/textarea.md
Customize with real content
Adapt the Haze textarea ui for our product. Replace the demo values of these props with our real content: id, name, rows, placeholder, autoGrow, required, class, ...rest. Keep the layout, the heading level rules and these accessibility details: With autoGrow the box has no resize handle and stops growing at 15 rem, then scrolls; browsers without field-sizing keep the fixed rows height. Resizing is limited to the vertical axis so a dragged box cannot push the form past a 320 px viewport. The component renders no label; pair it with Field or a label whose for matches the id. aria-invalid turns the border destructive, but also add an error message so the state is not shown by color alone. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using textarea, check it fits: use it when messages, comments, bios and release notes that run past one line; contact forms where the user explains a problem in their own words. Avoid it when short single-line values such as an email; use input; rich text with formatting, which needs an editor. Alternatives: @haze/input, @haze/field.
Dependencies
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.