codefast/ui

Command Palette

Search for a command to run...

Source
Form

Textarea

Multiline text input. Pair with Label and field utilities for accessible forms.

Examples

Button

Pair with Button to create a textarea with a submit button.

11 lines
import { Button } from "@codefast/ui/button";
import { Textarea } from "@codefast/ui/textarea";

export function TextareaButton() {
  return (
    <div className="grid w-full gap-2">
      <Textarea placeholder="Type your message here." />
      <Button>Send message</Button>
    </div>
  );
}

Disabled

Use the disabled prop to disable the textarea. To style the disabled state, add the data-disabled attribute to the Field component.

11 lines
import { Field, FieldLabel } from "@codefast/ui/field";
import { Textarea } from "@codefast/ui/textarea";

export function TextareaDisabled() {
  return (
    <Field data-disabled>
      <FieldLabel htmlFor="textarea-disabled">Message</FieldLabel>
      <Textarea id="textarea-disabled" placeholder="Type your message here." disabled />
    </Field>
  );
}

Field

Use Field, FieldLabel, and FieldDescription to create a textarea with a label and description.

Enter your message below.

12 lines
import { Field, FieldDescription, FieldLabel } from "@codefast/ui/field";
import { Textarea } from "@codefast/ui/textarea";

export function TextareaField() {
  return (
    <Field>
      <FieldLabel htmlFor="textarea-message">Message</FieldLabel>
      <FieldDescription>Enter your message below.</FieldDescription>
      <Textarea id="textarea-message" placeholder="Type your message here." />
    </Field>
  );
}

Invalid

Use the aria-invalid prop to mark the textarea as invalid. To style the invalid state, add the data-invalid attribute to the Field component.

Please enter a valid message.

12 lines
import { Field, FieldDescription, FieldLabel } from "@codefast/ui/field";
import { Textarea } from "@codefast/ui/textarea";

export function TextareaInvalid() {
  return (
    <Field data-invalid>
      <FieldLabel htmlFor="textarea-invalid">Message</FieldLabel>
      <Textarea id="textarea-invalid" placeholder="Type your message here." aria-invalid />
      <FieldDescription>Please enter a valid message.</FieldDescription>
    </Field>
  );
}

RTL

Right-to-left layout support for languages such as Arabic and Hebrew.

Translations are AI-generated for demonstration and may be imperfect.

شاركنا أفكارك حول خدمتنا.

46 lines
import { Field, FieldDescription, FieldLabel } from "@codefast/ui/field";
import { Textarea } from "@codefast/ui/textarea";

import type { Translations } from "#/features/components-catalog/components/detail/language";
import { useTranslation } from "#/features/components-catalog/components/detail/language-context";

const translations: Translations = {
  en: {
    dir: "ltr",
    values: {
      label: "Feedback",
      placeholder: "Your feedback helps us improve...",
      description: "Share your thoughts about our service.",
    },
  },
  ar: {
    dir: "rtl",
    values: {
      label: "التعليقات",
      placeholder: "تعليقاتك تساعدنا على التحسين...",
      description: "شاركنا أفكارك حول خدمتنا.",
    },
  },
  he: {
    dir: "rtl",
    values: {
      label: "משוב",
      placeholder: "המשוב שלך עוזר לנו להשתפר...",
      description: "שתף את מחשבותיך על השירות שלנו.",
    },
  },
};

export function TextareaRtl() {
  const { dir, t } = useTranslation(translations, "ar");

  return (
    <Field className="w-full max-w-xs" dir={dir}>
      <FieldLabel htmlFor="feedback" dir={dir}>
        {t.label}
      </FieldLabel>
      <Textarea id="feedback" placeholder={t.placeholder} dir={dir} rows={4} />
      <FieldDescription dir={dir}>{t.description}</FieldDescription>
    </Field>
  );
}

Usage

The minimal import and composition — see Examples below for styled, real-world variants.

5 lines
import { Textarea } from "@codefast/ui/textarea";

export function TextareaUsage() {
  return <Textarea placeholder="Type your message here." />;
}

Anatomy

How the parts nest — every slot the component exposes, in composition order.

Textarea

Features

  • Auto-grows to fit its content via the native field-sizing: content CSS property — no resize-observer JS needed.
  • Forwards every native <textarea> prop (rows, maxLength, controlled value/onChange).
  • Composes with Field/FieldLabel/FieldDescription for a labelled field, and with Button for a submit-style composer.

API reference

Props for each part of the component. All native element props are also forwarded.

Textarea

A multiline text input. Forwards all native textarea props.

rowsnumber

Initial visible height in lines.

maxLengthnumber

Hard cap on the number of characters.

valuestring

The controlled value.

onChangeReact.ChangeEventHandler<HTMLTextAreaElement>

Called when the value changes.

Accessibility

Built to be keyboard-navigable and screen-reader friendly out of the box.

  • Always pair with a Label via htmlFor / id.
  • If you show a counter, also enforce the limit with maxLength.
  • Use aria-describedby to link helper or error text.

Guidelines

Conventions that keep usage consistent across an app.

Do

  • Use for free-form, multi-line input like notes and bios.
  • Show a counter when there’s a length limit.

Don’t

  • Don’t use a textarea for single-line input — use Input.
  • Don’t disable resize unless the layout truly requires it.

Explore further

Ready to integrate?

Follow the Getting Started guide to install @codefast/ui, or browse the full component gallery.