A multiline text field for notes, messages, and longer responses.
Default
Shown in the changelog and weekly customer digest.
Variants & Labels
Growing Composer
Canary 10% looks healthy — latency p95 is down 14ms.
Form & Validation
States
Add the failing service and mitigation steps before closing the incident.
Read-only fields can still be selected and copied.
Purpose
A textarea lets people write and edit several lines of text, such as a message, a note, or a longer answer.
Parts & Composition
Textarea renders one native multiline field with optional label, icon, and description. Use its label and description props for a self-contained control. To compose a form field with a separate label and description, place it with FieldLabel and FieldDescription inside UI SDK Field.
API & Props
| Prop | Purpose |
|---|---|
variant | filled / outline / ghost / underline. Defaults to filled. |
size | xs / sm / md / lg. Defaults to md. Sets the text scale, padding, and minimum height. |
label / labelVariant | Visible label. Choose standard, floating, or wave. |
description | Associates helper or validation text with the field. |
icon / iconPosition | Decorative icon at the logical start or end. |
waveDelay | Delay per character in milliseconds. Defaults to 24 and caps the total stagger. |
rows / autoResize | Sets the initial visible rows, default 3. Enable autoResize to follow the text height. |
value / defaultValue / onValueChange | Controlled string, initial string, and SDK change callback. |
submitShortcut / onSubmit | Use enter or mod+enter to submit through the callback or the associated form. |
className / ref / containerProps | Style or reference the field. Use containerProps for outer layout (textarea-container defaults to w-full min-w-0). |
render / controller | Customize rendering or use createInputController() to read, set, clear, or focus the field. |
Native textarea props such as name, form, required, readOnly, disabled, and maxLength pass through.
Add name to include the text in form submission. Form reset restores the uncontrolled default. For controlled text, update the string in onValueChange. Enter adds a line by default.
Theming, Layout & Responsiveness
Uses the same semantic surfaces and focus styling as Input, including an animated underline and thin scrollbars. Use aria-invalid for an invalid field and description for the message. The field and its container expose data-size and data-variant for theme overrides.
The size sets a minimum height without limiting the number of lines. Vertical resizing is available by default. With autoResize, set a maximum height to make longer content scroll.
Motion & Accessibility
Floating labels, wave labels, and the underline respect reduced motion.
Pass a visible label or give the field an accessible name. The description is added to any existing aria-describedby references. Explain a submit shortcut near the field if you enable one.
Guidance for Coding Agents
Install Textarea using the command in the Install tab and read this Info page and the upstream UI SDK Textarea reference before implementing. Use Textarea for multiline entry and start from the closest Preview example. Name the field for form submission and choose controlled or uncontrolled state according to the app’s needs. For a growing composer, enable autoResize, set a maximum height, and use mod+enter so Enter still adds a line.
Use label and description for a self-contained field, or compose Textarea with the UI SDK Field parts when the form needs shared validation or layout. Use the API table for component options and consult the upstream reference for inherited native props, callbacks, controller behavior, rendering, and keyboard shortcuts.
CLI installation
bunx --bun shadcn@latest add https://ui.devvarena.com/api/r/textarea'use client';
import { Textarea as SDKTextarea } from '@ui-sdk/react/textarea';
import { cva, type VariantProps } from 'class-variance-authority';
import { type ComponentProps, type ReactNode, useId, useMemo } from 'react';
import {
clampWaveDelay,
controlMinHeights,
controlTextSizes,
focusRing,
getTextFieldIconPadding,
partClass,
type StandardControlSize,
textFieldLabelSegmenter,
textFieldLayout,
textFieldSurfaces,
textFieldUnderlineMotion,
} from '@/lib/devvarena-ui';
import { cn } from '@/lib/utils';
const textareaVariants = cva(
`block w-full min-w-0 rounded-lg border py-2 shadow-sm [scrollbar-width:thin] [scrollbar-color:var(--border)_transparent] transition-[border-color,background-color,box-shadow,filter] duration-200 ${focusRing} disabled:cursor-not-allowed disabled:opacity-50 read-only:cursor-default motion-reduce:transition-none`,
{
variants: {
variant: {
...textFieldSurfaces,
underline: `${textFieldSurfaces.underline} ${textFieldUnderlineMotion}`,
},
size: {
xs: `${controlMinHeights.xs} px-2 ${controlTextSizes.xs}`,
sm: `${controlMinHeights.sm} px-2.5 ${controlTextSizes.sm}`,
md: `${controlMinHeights.md} px-3 ${controlTextSizes.md}`,
lg: `${controlMinHeights.lg} px-4 ${controlTextSizes.lg}`,
},
},
defaultVariants: { variant: 'filled', size: 'md' },
},
);
type TextareaSize = StandardControlSize;
type NativeTextareaProps = ComponentProps<typeof SDKTextarea>;
type TextareaProps = NativeTextareaProps &
VariantProps<typeof textareaVariants> & {
label?: string;
labelVariant?: 'standard' | 'floating' | 'wave';
icon?: ReactNode;
iconPosition?: 'start' | 'end';
/** Per-grapheme delay in milliseconds; total staggering is capped at 300ms. */
waveDelay?: number;
description?: ReactNode;
/** Native props/ref for the outer layout; className/ref target the textarea itself. */
containerProps?: Omit<ComponentProps<'div'>, 'children'>;
};
const labelActive =
'has-[textarea:focus]:[--field-label-scale:0.85] has-[textarea:not(:placeholder-shown)]:[--field-label-scale:0.85]';
const labelMotion =
'inline-block origin-left scale-[var(--field-label-scale,1)] backdrop-blur-xs transition-[scale,color] duration-200 ease-out group-has-[textarea:focus]/field:text-primary group-data-invalid/field:text-destructive motion-reduce:transition-none rtl:origin-right';
const waveMotion =
'inline-block origin-left scale-[var(--field-label-scale,1)] backdrop-blur-xs transition-[translate,scale,color] duration-200 ease-out group-has-[textarea:focus]/field:-translate-y-4 group-has-[textarea:focus]/field:text-primary group-has-[textarea:not(:placeholder-shown)]/field:-translate-y-4 group-data-invalid/field:text-destructive motion-reduce:transition-none rtl:origin-right';
function TextareaLabel({ className, ...props }: ComponentProps<'label'>) {
// biome-ignore lint/a11y/noLabelWithoutControl: htmlFor and label children are supplied by callers via props.
return <label {...props} data-slot="textarea-label" className={className} />;
}
function TextareaDescription({ className, ...props }: ComponentProps<'p'>) {
return <p {...props} data-slot="textarea-description" className={cn('m-0 mt-1', className)} />;
}
/** Chrome wrapper for icons, floating labels, and underline affordances. */
function TextareaControlShell({ className, ...props }: ComponentProps<'div'>) {
return <div data-slot="textarea-control" className={className} {...props} />;
}
/** One native textarea contract; label position comes from CSS, including autofilled values. */
function Textarea({
label,
labelVariant = 'standard',
variant = 'filled',
size = 'md',
rows = 3,
autoResize,
icon,
iconPosition = 'start',
waveDelay = 24,
description,
containerProps,
id,
placeholder,
className,
'aria-describedby': describedBy,
...props
}: TextareaProps) {
const generatedId = useId();
const textareaId = id ?? generatedId;
const descriptionId = `${textareaId}-description`;
const animated = Boolean(label) && labelVariant !== 'standard';
const hasDescription = description !== undefined && description !== null && description !== false;
const invalid = Boolean(props['aria-invalid']) && props['aria-invalid'] !== 'false';
const graphemes = useMemo(
() =>
labelVariant === 'wave' && label ? Array.from(textFieldLabelSegmenter.segment(label)) : [],
[label, labelVariant],
);
const delay = clampWaveDelay(waveDelay, graphemes.length);
const underline = variant === 'underline';
const resolvedSize: TextareaSize = size ?? 'md';
const paddingForIcon = icon ? getTextFieldIconPadding(iconPosition, underline) : undefined;
return (
<div
{...containerProps}
data-slot="textarea-container"
data-size={resolvedSize}
data-variant={variant}
data-disabled={props.disabled ? '' : undefined}
data-invalid={invalid || undefined}
className={cn('w-full min-w-0', animated && 'pt-2', containerProps?.className)}
>
{label && !animated && (
<TextareaLabel
htmlFor={textareaId}
className={cn(
'mb-2 block font-medium leading-5',
controlTextSizes[resolvedSize],
invalid && 'text-destructive',
props.disabled && 'opacity-50',
)}
>
{label}
</TextareaLabel>
)}
<TextareaControlShell
data-variant={variant}
data-size={resolvedSize}
data-invalid={invalid || undefined}
className={cn('group/field relative', animated && labelActive)}
>
<SDKTextarea
{...props}
id={id ?? (label ? textareaId : undefined)}
data-size={resolvedSize}
data-variant={variant}
rows={rows}
autoResize={autoResize}
placeholder={animated ? ' ' : placeholder}
aria-describedby={
[describedBy, hasDescription ? descriptionId : undefined].filter(Boolean).join(' ') ||
undefined
}
className={partClass(
textareaVariants({ variant, size: resolvedSize }),
autoResize ? 'resize-none' : 'resize-y',
paddingForIcon,
className,
)}
/>
{animated && label && (
<TextareaLabel
htmlFor={textareaId}
className={cn(
'pointer-events-none absolute top-2 leading-5 text-muted-foreground motion-reduce:transition-none',
labelVariant === 'floating' &&
'transition-[top] duration-200 ease-out group-has-[textarea:focus]/field:top-0 group-has-[textarea:focus]/field:-translate-y-1/2 group-has-[textarea:not(:placeholder-shown)]/field:top-0 group-has-[textarea:not(:placeholder-shown)]/field:-translate-y-1/2',
'max-w-[calc(100%-1.5rem)]',
controlTextSizes[resolvedSize],
icon && iconPosition === 'start'
? underline
? textFieldLayout.floatingUnderlineIcon
: textFieldLayout.floatingWithIcon
: underline
? '-start-1'
: textFieldLayout.floatingStart,
icon && 'max-w-[calc(100%-3.25rem)]',
props.disabled && 'opacity-50',
)}
>
<span className="sr-only">{label}</span>
<span
aria-hidden="true"
className="-my-6 block overflow-hidden text-ellipsis whitespace-pre px-1 py-6"
>
{labelVariant === 'wave' ? (
graphemes.map(({ segment, index: offset }, index) => (
<span
key={`${label}-${offset}`}
className={waveMotion}
style={{ transitionDelay: `${index * delay}ms` }}
>
{segment === ' ' ? '\u00A0' : segment}
</span>
))
) : (
<span className={labelMotion}>{label}</span>
)}
</span>
</TextareaLabel>
)}
{icon && (
<span
aria-hidden="true"
className={cn(
'pointer-events-none absolute top-2.5 inline-flex items-center justify-center text-muted-foreground transition-colors duration-200 group-has-[textarea:focus]/field:text-primary group-data-invalid/field:text-destructive motion-reduce:transition-none [&>svg]:size-full',
textFieldLayout.icon,
iconPosition === 'start'
? underline
? 'start-0'
: textFieldLayout.iconStart
: underline
? 'end-0'
: textFieldLayout.iconEnd,
props.disabled && 'opacity-50',
)}
>
{icon}
</span>
)}
</TextareaControlShell>
{hasDescription && (
<TextareaDescription
id={descriptionId}
className={cn(
'mt-1 text-xs leading-relaxed',
invalid ? 'text-destructive' : 'text-muted-foreground',
)}
>
{description}
</TextareaDescription>
)}
</div>
);
}
export type { InputController, TextareaState, TextareaSubmitDetails } from '@ui-sdk/react/textarea';
export { createInputController } from '@ui-sdk/react/textarea';
export { Textarea, type TextareaProps, type TextareaSize, textareaVariants };
import { cn } from '@/lib/utils';
type ClassValue = string | false | null | undefined;
type PartClassValue<State> = ClassValue | ((state: State) => ClassValue);
/** Composes static class names and UI-SDK state class functions into a single `className` prop. */
export function partClass<State>(...parts: PartClassValue<State>[]) {
if (parts.some((part) => typeof part === 'function')) {
return (state: State) =>
cn(...parts.map((part) => (typeof part === 'function' ? part(state) : part)));
}
return cn(...(parts as ClassValue[]));
}
export const surfacePadding = 'p-1 [--surface-padding:1.5rem] [--concentric-inset:0.25rem]';
export const surfaceRegionInset = 'p-[calc(var(--surface-padding,1rem)-0.5rem)]';
export const surfaceHeaderRadius = 'rounded-t-[max(0px,calc(var(--radius-lg,0.5rem)-0.25rem))]';
export const surfaceFooterRadius = 'rounded-b-[max(0px,calc(var(--radius-lg,0.5rem)-0.25rem))]';
/** Concentric inner radius (`outer - inset`); set `[--concentric-inset:0.125rem]` on `p-0.5` rails (defaults to `0.25rem` for `p-1`). */
export const concentricRadius =
'rounded-[max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem)))]';
export const surfaceBodyPadding =
'py-[max(0px,calc(var(--surface-padding,1rem)-1rem))] has-[>[data-slot=list]:not([data-variant=plain])]:p-0 has-[>[data-slot=list-items-container]]:p-0';
export type StandardControlSize = 'xs' | 'sm' | 'md' | 'lg';
/** Standard control heights (`28px / 32px / 40px / 48px`) for buttons, inputs, selects, tabs, and sliders. */
export const controlHeights = {
xs: 'h-7',
sm: 'h-8',
md: 'h-10',
lg: 'h-12',
} as const satisfies Record<StandardControlSize, string>;
/** Standard minimum control heights (`28px / 32px / 40px / 48px`) for expandable controls and menu items. */
export const controlMinHeights = {
xs: 'min-h-7',
sm: 'min-h-8',
md: 'min-h-10',
lg: 'min-h-12',
} as const satisfies Record<StandardControlSize, string>;
/** Standard control text sizes (`xs / xs / sm / base`) paired with `StandardControlSize`. */
export const controlTextSizes = {
xs: 'text-xs',
sm: 'text-xs',
md: 'text-sm',
lg: 'text-base',
} as const satisfies Record<StandardControlSize, string>;
/** Compact control heights (`1.25rem / 1.3rem / 1.625rem / 1.75rem`), one step smaller than standard, for switches and compact controls. */
export const compactControlHeights = {
xs: 'h-[1.3rem]',
sm: 'h-[1.4rem]',
md: 'h-[1.5rem]',
lg: 'h-[1.6rem]',
} as const satisfies Record<StandardControlSize, string>;
/** Compact minimum control heights (`1rem / 1.25rem / 1.5rem / 1.75rem`) for badges and tooltips. */
export const compactControlMinHeights = {
xs: 'min-h-[1.3rem]',
sm: 'min-h-[1.4rem]',
md: 'min-h-[1.5rem]',
lg: 'min-h-[1.6rem]',
} as const satisfies Record<StandardControlSize, string>;
/** Universal keyboard focus + invalid ring/border styles shared across controls. */
export const focusRing =
'touch-manipulation outline-none focus-visible:border-ring/30 transition-ring focus-visible:ring-3 focus-visible:ring-ring/15 focus-visible:brightness-[0.97] dark:focus-visible:brightness-[1.15] has-[:focus-visible]:border-ring/30 has-[:focus-visible]:ring-3 has-[:focus-visible]:ring-ring/15 has-[:focus-visible]:brightness-[0.97] dark:has-[:focus-visible]:brightness-[1.15] data-active:border-ring/30 data-active:ring-3 data-active:ring-ring/15 data-active:brightness-[0.97] dark:data-active:brightness-[1.15] data-open:border-ring/30 data-open:ring-3 data-open:ring-ring/15 data-open:brightness-[0.97] dark:data-open:brightness-[1.15] data-disabled:cursor-not-allowed data-disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/25 data-invalid:border-destructive data-invalid:ring-3 data-invalid:ring-destructive/25 has-[[data-invalid]]:border-destructive has-[[data-invalid]]:ring-3 has-[[data-invalid]]:ring-destructive/25 group-aria-invalid/control:border-destructive group-aria-invalid/control:ring-3 group-aria-invalid/control:ring-destructive/25 group-data-invalid/control:border-destructive group-data-invalid/control:ring-3 group-data-invalid/control:ring-destructive/25 group-has-[input[aria-invalid=true]]/control:border-destructive group-has-[input[aria-invalid=true]]/control:ring-3 group-has-[input[aria-invalid=true]]/control:ring-destructive/25 hover:brightness-[0.97] dark:hover:brightness-[1.15]';
/** Shared sliding highlight indicator base (pointer-safe, concentric inner radius inside rounded-lg containers, 200ms transition). */
export const slidingHighlight =
'pointer-events-none -z-10 rounded-[max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem)))] bg-primary/10 [clip-path:inset(0px_round_max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem))))] transition-[transform,width,height,opacity] duration-200 ease-out motion-reduce:transition-none';
export const textFieldSurfaces = {
filled: 'border-input bg-card text-card-foreground',
outline: 'border-input bg-transparent text-foreground dark:bg-transparent',
ghost: 'border-transparent bg-muted text-foreground shadow-none',
underline:
'rounded-none border-0 border-b-2 border-input bg-transparent px-0 text-foreground shadow-none focus-visible:border-ring focus-visible:ring-0 aria-invalid:ring-0 data-invalid:ring-0 dark:bg-transparent',
} as const;
export const textFieldUnderlineMotion =
'border-transparent! bg-origin-border bg-bottom bg-no-repeat [--underline-color:var(--primary)] [background-image:linear-gradient(var(--underline-color),var(--underline-color)),linear-gradient(var(--input),var(--input))] [background-size:0%_2px,100%_2px] focus:[background-size:100%_2px,100%_2px] aria-invalid:[--underline-color:var(--destructive)] data-invalid:[--underline-color:var(--destructive)] transition-[border-color,background-color,box-shadow,filter,background-size] duration-200 motion-reduce:transition-none';
/** Generic balanced icon & floating-label layout tokens shared across all text-field sizes. */
export const textFieldLayout = {
icon: 'size-4',
iconStart: 'start-3',
iconEnd: 'end-3',
padStart: 'ps-9',
padEnd: 'pe-9',
underlinePadStart: 'ps-7',
underlinePadEnd: 'pe-7',
floatingStart: 'start-2.5',
floatingWithIcon: 'start-8',
floatingUnderlineIcon: 'start-6',
} as const;
export const textFieldLabelSegmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
/** Clamps per-grapheme wave delay (ms) so total staggering stays within 300ms. */
export function clampWaveDelay(waveDelay: number, count: number): number {
return Math.max(
0,
Math.min(Number.isFinite(waveDelay) ? waveDelay : 24, 80, 300 / Math.max(1, count - 1)),
);
}
/** Shared scale/color transition for floating labels inside a `group/field` wrapper. */
export const textFieldLabelMotion =
'inline-block origin-left backdrop-blur-xs transition-[scale,color] duration-200 ease-out group-has-[input:focus]/field:scale-85 group-has-[input:not(:placeholder-shown)]/field:scale-85 rtl:origin-right motion-reduce:transition-none';
/** Resolves start/end padding for a text field when a leading or trailing icon is present. */
export function getTextFieldIconPadding(iconPosition: 'start' | 'end', underline: boolean): string {
if (iconPosition === 'start') {
return underline ? textFieldLayout.underlinePadStart : textFieldLayout.padStart;
}
return underline ? textFieldLayout.underlinePadEnd : textFieldLayout.padEnd;
}
/** Shared per-grapheme ripple transition for wave labels inside a `group/field` wrapper. */
export const textFieldWaveMotion =
'inline-block origin-left backdrop-blur-xs transition-[translate,scale,color] duration-200 ease-out group-has-[input:focus]/field:-translate-y-5 group-has-[input:focus]/field:scale-85 group-has-[input:focus]/field:text-primary group-has-[input:not(:placeholder-shown)]/field:-translate-y-5 group-has-[input:not(:placeholder-shown)]/field:scale-85 group-has-[input[aria-invalid=true]]/field:text-destructive rtl:origin-right motion-reduce:transition-none';