Components · Forms
Textarea
A multi-line field that grows with its content.
39% of the 2,062 sites in The UI Index have a form (806 sites).
Both previews render the same markup; the HTML tab below is that markup without a framework.
Install
- React
- npx shadcn@
latest add https:// www.themes.dev/ caseroom/ r/ textarea.json - Astro
- npx shadcn@
latest add https:// www.themes.dev/ caseroom/ r/ astro/ textarea.json
Or copy the files below into your project. They need clsx, tailwind-merge, and the Caseroom theme. The HTML needs only the compiled CSS.
import type { TextareaHTMLAttributes } from 'react';
import { cn } from '@/lib/utils';
import { fieldClasses } from '../input/input.variants';
export type TextareaProps = TextareaHTMLAttributes<HTMLTextAreaElement>;
/** A multi-line field that grows with its content where the browser supports field-sizing. */
export function Textarea({ className, ...props }: TextareaProps) {
return <textarea className={cn(fieldClasses, 'min-h-20 py-2 [field-sizing:content]', className)} {...props} />;
}---
import type { HTMLAttributes } from 'astro/types';
import { cn } from '@/lib/utils';
import { fieldClasses } from '../input/input.variants';
type Props = HTMLAttributes<'textarea'>;
const { class: className, ...rest } = Astro.props;
---
<textarea class={cn(fieldClasses, 'min-h-20 py-2 [field-sizing:content]', className)} {...rest}><slot /></textarea><div class="grid w-full max-w-sm gap-2">
<label class="flex items-center gap-2 text-sm leading-none font-medium has-[input]:items-start has-[input]:leading-snug has-[input]:[&>*:first-child]:mt-px select-none peer-disabled:cursor-not-allowed peer-disabled:opacity-50" for="ex-message">
Message
</label>
<textarea class="w-full min-w-0 rounded-md border border-input bg-background px-3 text-sm text-foreground transition-colors placeholder:text-muted-foreground enabled:hover:border-foreground/85 enabled:active:bg-muted aria-invalid:enabled:hover:border-destructive aria-invalid:enabled:hover:bg-[color-mix(in_oklab,var(--destructive)_6%,var(--background))] aria-invalid:enabled:active:bg-[color-mix(in_oklab,var(--destructive)_10%,var(--background))] focus-visible:border-ring focus-visible:outline-2 focus-visible:outline-offset-0 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:outline-destructive min-h-20 py-2 [field-sizing:content]" id="ex-message" placeholder="What can we help with?">
</textarea>
</div>