Forms
Textarea
Textarea wraps a native <textarea> with the same field chrome as Input — label, helpText, error, and size variants.
Installation
npx shadcn add https://rck.vibeboxph.com//r/textarea.jsonLive preview & controls
Controls
<Textarea label="Message" placeholder="Write a message…" />Anatomy
FieldLabelBuilt-in top field label.textareaThe native multiline field.FieldMessageHelp text or error message below the field.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| label | React.ReactNode | — | Field label. |
| helpText | React.ReactNode | — | Supplementary help text shown when there's no error. |
| error | React.ReactNode | — | Error text; sets `aria-invalid` and destructive styling. |
| size | "sm" | "md" | "lg" | md | Typography and padding scale. |
| value / defaultValue | string | — | Controlled / uncontrolled value. |
| onValueChange | (value: string) => void | — | Convenience change handler. |
| disabled | boolean | — | Native disabled state. |
| rows | number | — | Native rows attribute. |
Accessibility
- Label is associated via `htmlFor`/`id` (auto-generated with `useId` when not provided).
- `error` sets `aria-invalid` and `aria-describedby` pointing at the message with `role="alert"`.
- Use `helpText` for supplementary guidance that shouldn't interrupt on every focus.
Source
registry/rck/ui/textarea.tsx
"use client";
import * as React from "react";
import { cn } from "@/lib/utils";
import {
fieldWrapperVariants,
FieldLabel,
FieldMessage,
type FieldWrapperVariantProps,
} from "@/registry/rck/ui/field-chrome";
export interface TextareaProps
extends React.TextareaHTMLAttributes<HTMLTextAreaElement>, FieldWrapperVariantProps {
label?: React.ReactNode;
helpText?: React.ReactNode;
error?: React.ReactNode;
containerClassName?: string;
onValueChange?: (value: string) => void;
}
export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
(
{
className,
containerClassName,
size,
label,
helpText,
error,
required,
id: providedId,
onChange,
onValueChange,
disabled,
...props
},
ref,
) => {
const generatedId = React.useId();
const id = providedId ?? generatedId;
const helpTextId = helpText ? `${id}-help-text` : undefined;
const errorId = error ? `${id}-error` : undefined;
const invalid = Boolean(error);
return (
<div
data-slot="textarea-container"
className={cn("flex flex-col gap-1.5", containerClassName)}
>
{label && (
<FieldLabel htmlFor={id} required={required}>
{label}
</FieldLabel>
)}
<textarea
ref={ref}
id={id}
data-slot="textarea"
disabled={disabled}
required={required}
aria-invalid={invalid || undefined}
aria-describedby={cn(helpTextId, errorId) || undefined}
className={cn(
fieldWrapperVariants({ size, invalid }),
"placeholder:text-muted-foreground h-auto min-h-20 items-start py-2 outline-none disabled:cursor-not-allowed",
className,
)}
onChange={(event) => {
onChange?.(event);
onValueChange?.(event.target.value);
}}
{...props}
/>
{helpText && !error && <FieldMessage id={helpTextId}>{helpText}</FieldMessage>}
{error && (
<FieldMessage id={errorId} invalid role="alert">
{error}
</FieldMessage>
)}
</div>
);
},
);
Textarea.displayName = "Textarea";
registry/rck/ui/field-chrome.tsx
import * as React from "react";
import { cva, type VariantProps } from "@/lib/cva";
import { cn } from "@/lib/utils";
export const fieldWrapperVariants = cva(
"flex w-full items-center gap-2 rounded-md border bg-background px-3 shadow-sm " +
"transition-colors has-[input:disabled]:cursor-not-allowed has-[input:disabled]:opacity-50 " +
"has-[textarea:disabled]:cursor-not-allowed has-[textarea:disabled]:opacity-50",
{
variants: {
size: {
sm: "h-8 text-[10px]",
md: "h-[39px] text-[11px]",
lg: "h-11 text-xs",
},
invalid: {
true: "border-destructive focus-within:ring-2 focus-within:ring-destructive/40",
false:
"border-border-strong focus-within:border-primary focus-within:ring-2 focus-within:ring-ring/30",
},
},
defaultVariants: {
size: "md",
invalid: false,
},
},
);
/** Built-in field label — shared by Input, Textarea, and boolean field wrappers. */
export function FieldLabel({
className,
required,
children,
...props
}: React.LabelHTMLAttributes<HTMLLabelElement> & { required?: boolean }) {
return (
<label
data-slot="field-label"
className={cn("text-foreground text-sm leading-none font-medium", className)}
{...props}
>
{children}
{required && <span className="text-destructive ml-0.5">*</span>}
</label>
);
}
export function FieldMessage({
className,
invalid,
...props
}: React.HTMLAttributes<HTMLParagraphElement> & { invalid?: boolean }) {
return (
<p
data-slot="field-message"
className={cn(
"text-xs",
invalid ? "text-destructive" : "text-muted-foreground",
className,
)}
{...props}
/>
);
}
export type ControlPosition = "start" | "end";
export interface BooleanGroupOption {
value: string;
/** Inline label beside the control. */
text: string;
disabled?: boolean;
helpText?: React.ReactNode;
}
export interface BooleanFieldLayoutProps {
label?: React.ReactNode;
text?: React.ReactNode;
helpText?: React.ReactNode;
error?: React.ReactNode;
required?: boolean;
/** Places the control at inline-start (default) or inline-end — flips automatically in RTL. */
controlPosition?: ControlPosition;
disabled?: boolean;
id?: string;
className?: string;
containerClassName?: string;
children: (args: {
id: string;
describedBy?: string;
disabled?: boolean;
}) => React.ReactNode;
}
export function BooleanFieldLayout({
label,
text,
helpText,
error,
required,
controlPosition = "start",
disabled,
id: providedId,
className,
containerClassName,
children,
}: BooleanFieldLayoutProps) {
const generatedId = React.useId();
const id = providedId ?? generatedId;
const helpTextId = helpText && !error ? `${id}-help-text` : undefined;
const errorId = error ? `${id}-error` : undefined;
const describedBy = cn(helpTextId, errorId) || undefined;
const control = children({ id, describedBy, disabled });
return (
<div
data-slot="boolean-field"
className={cn("flex flex-col gap-1.5", containerClassName)}
>
{label && (
<FieldLabel htmlFor={id} required={required}>
{label}
</FieldLabel>
)}
<div
className={cn(
"flex w-full items-start gap-2",
controlPosition === "end" && "flex-row-reverse justify-between",
className,
)}
>
{control}
{text && (
<label
htmlFor={id}
className={cn(
"text-foreground text-sm leading-none font-medium",
controlPosition === "end" && "flex-1",
disabled && "cursor-not-allowed opacity-50",
)}
>
{text}
</label>
)}
</div>
{helpText && !error && <FieldMessage id={helpTextId}>{helpText}</FieldMessage>}
{error && (
<FieldMessage id={errorId} invalid role="alert">
{error}
</FieldMessage>
)}
</div>
);
}
export type FieldWrapperVariantProps = VariantProps<typeof fieldWrapperVariants>;
Related examples
Sizes & help textDefault and large textarea with helper text.
ValidationLive character-count validation.