Skip to content

Textarea

Textarea

A multi-line text input with Fluent styling (resize vertical by default, accessible bottom stroke, primary bottom border while focused). Inside a Field it picks up the label, hint, error, required (native attribute) and invalid state automatically.

size resolves from its own prop, then the surrounding Field's size, then WaveProvider inputDefaults.size, else 'medium'; appearance from its own prop, then WaveProvider inputDefaults.appearance, else 'outline'; both render as data-size and data-appearance on the textarea element.

Examples

Default

export const Default: Story = {};

Error

Description is required
export const Error: Story = {
  args: {
    'aria-label': 'Description',
    placeholder: 'Description',
    error: 'Description is required',
  },
};

Disabled

export const Disabled: Story = {
  args: {
    placeholder: 'Disabled',
    disabled: true,
  },
};

Sizes And Appearances

export const SizesAndAppearances: Story = {
  render: (args) => (
    <SizeAppearanceGrid
      render={(size, appearance) => (
        <Textarea
          {...args}
          rows={2}
          size={size}
          appearance={appearance}
          aria-label={`${size} ${appearance}`}
        />
      )}
    />
  ),
};

Resize

export const Resize: Story = {
  render: (args) => (
    <div className="flex flex-col gap-4">
      {(['none', 'vertical', 'horizontal', 'both'] as const).map((resize) => (
        <Textarea {...args} key={resize} rows={2} resize={resize} aria-label={`resize ${resize}`} />
      ))}
    </div>
  ),
};

Controlled

0 characters
export const Controlled: Story = {
  render: function Render(args) {
    const [value, setValue] = useState('');
    return (
      <div className="flex flex-col gap-2">
        <Textarea {...args} value={value} onValueChange={setValue} />
        <span className="text-wave-caption-1 text-wave-muted-foreground">
          {value.length} characters
        </span>
      </div>
    );
  },
};

Props

NameTypeRequiredDefaultDescription
errorstring | booleanNo

Validation error.
- A non-empty string renders the message in a role="alert" element **after** the textarea (a sibling, so ref and className stay on the textarea) and links it through aria-describedby and aria-errormessage. Inside a Field that renders its own error, the message is not repeated.
- true only marks the textarea invalid (aria-invalid and the error border), as in 0.4.

The error border also shows whenever the textarea ends up aria-invalid="true" without this prop (an error on the surrounding Field, or your own aria-invalid). Your own aria-invalid={false} (or "false") wins over this prop: the textarea is reported valid and shows neither the error border nor the message.

errorMessagePropsInputErrorMessagePropsNo

Props of the error message element (id, className, …) rendered for a string error.

size'small' | 'medium' | 'large'No

Size of the field, a minimum height with its type ramp: small (64px, Caption 1 text), medium (80px, Body 1) or large (96px, Body 2). Default: the surrounding Field's size, else WaveProvider inputDefaults.size, else 'medium'.

appearance'outline' | 'underline' | 'filled-darker' | 'filled-lighter'No

Look of the field: outline (a full border), underline (a bottom stroke only), filled-darker or filled-lighter (a fill without a visible stroke: give the field a visible label). Default: WaveProvider inputDefaults.appearance, else 'outline'.

resize'none' | 'vertical' | 'horizontal' | 'both'No'vertical'

Which directions the user can drag the corner handle to resize the field in (Fluent UI's resize): none, vertical, horizontal or both. Default: 'vertical', the height-only resize WaveUI has always drawn (Fluent's default is 'none').

onValueChange(value: string) => voidNo

Called with the new string value on every change, next to the native onChange event handler (onValueChange={setNote} instead of onChange={(e) => setNote(e.target.value)}; Fluent UI's onChange(event, data) with data.value).

refReact.Ref<HTMLTextAreaElement>No

Ref to the <textarea> element.

Any other prop is passed to the element it renders (HTMLTextAreaElement).

Stable class names

PartClass
rootwave-textarea
errorMessagewave-textarea__error-message