Textarea for Astro
Native Astro multiline fields with shared focus and error styles.
Installation
bunx --bun shadcn@latest add @gnostic/textareanpx shadcn@latest add @gnostic/textareapnpm dlx shadcn@latest add @gnostic/textareaComponent classes: Default Gnostic.
Complete the Installation guide first. Then copy the component files below.
No extra packages are required.
Copy the files
src/components/ui/textarea/index.ts
export { default as Textarea } from "./textarea.astro"
src/components/ui/textarea/textarea.astro
---
import type { HTMLAttributes } from "astro/types"
import { cn } from "cn"
type Props = HTMLAttributes<"textarea">
const {
class: className,
"data-slot": dataSlot = "textarea",
...props
} = Astro.props
---
<textarea data-slot={dataSlot} class={cn("font-sans border-input bg-background text-foreground ring-ring/24 placeholder:text-muted-foreground/72 dark:bg-input/32 focus-visible:border-ring aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/16 dark:aria-invalid:ring-destructive/24 field-sizing-content min-h-18 w-full rounded-lg border px-[calc(--spacing(3)-1px)] py-[calc(--spacing(1.5)-1px)] text-base shadow-xs/5 transition-shadow outline-none not-disabled:not-focus-visible:not-aria-invalid:inset-shadow-[0_1px_--theme(--color-black/4%)] focus-visible:shadow-none focus-visible:ring-[3px] disabled:opacity-64 max-sm:min-h-21 sm:text-sm dark:not-disabled:not-focus-visible:not-aria-invalid:inset-shadow-[0_-1px_--theme(--color-white/6%)]", className)} {...props}>
</textarea>
Usage
import { Textarea } from "@/components/ui/textarea"
<Textarea placeholder="Type your message here..." />
Notes
- Use
Textareafor longer free-form input where multiple lines are expected. - Set
rowswhen you want a clearer default height. - Pair it with Field when you need descriptions or validation messaging.
Example
<Textarea rows={6} placeholder="Write your message..." />
Sizes and states
API Reference
Read the installed source for the complete prop types.
When to use Textarea
Use Textarea for messages, notes, and other values that need several lines. Provide a visible label, name, and useful initial height. Put initial text in the default slot as required by native textarea markup.
Keyboard and behavior
Browser editing, selection, form submission, and disabled behavior remain native. Set aria-invalid only with a corresponding explanation. Length limits should be stated before the user reaches them.
Theme and layout
The single element owns its surface styles and can grow with content according to its CSS. Check resize behavior and long unbroken text. Use classes for width and height rather than importing a React control wrapper.