Inputs & controlsbeta

    Textarea

    A component for displaying textareas.

    Follow the installation and quick start below to use Textarea in your project, or read the complete setup guide.

    Accessible by designLight & darkCopy. Customize. Ship.
    On this page
    Live previewFluid

    0/280 characters

    Interactive exampleReact / TypeScript / Tailwind CSS
    ADD TO YOUR PROJECT

    Installation

    1. Initialize once

    Run from an existing React project with Node.js 18 or later. Skip this step if the project already has u-lib.json. Initialization copies the shared stylesheet and adds its import to your application entry.

    npx @scriptwithahmad/u-lib@0.2.2 init

    2. Add Textarea and example components

    This command includes the UI components used by this page's usage examples. The CLI copies editable source into your components directory and installs each component's dependencies. Existing source files are preserved.

    npx @scriptwithahmad/u-lib@0.2.2 add textarea button label

    Choose the tab for your package manager. Yarn commands require modern Yarn; Yarn Classic users can use npx. Use --dry-run to preview changes. See the installation guide for custom paths, JavaScript output and package-import alternatives.

    USE IN YOUR APP

    Quick start

    Copy this example into src/Example.tsx (or Example.tsx at the project root when you do not use src). Imports assume the default CLI paths. From a nested file such as src/app/page.tsx, adjust ./components to ../components. Keep the client directive in Next.js when using state or event handlers.

    textarea-example.tsx
    "use client";
    import { useId, useState } from "react";
    import { Button } from "./components/ui/button";
    import { Label } from "./components/ui/label";
    import { Textarea } from "./components/ui/textarea";
    export default function TextareaUi() {
      const id = useId();
      const [message, setMessage] = useState("");
      const [sent, setSent] = useState(false);
      return <form className="w-full max-w-sm space-y-3" onSubmit={(event) => { event.preventDefault(); setSent(true); }}>
        <Label htmlFor={id}>Your feedback</Label>
        <Textarea id={id} placeholder="Tell us what you think..." required maxLength={280} value={message} onChange={(event) => { setMessage(event.target.value); setSent(false); }} />
        <div className="flex items-center justify-between gap-3"><p className="text-sm text-muted-foreground">{message.length}/280 characters</p><Button type="submit" disabled={!message.trim()}>Send feedback</Button></div>
        {sent && <p role="status" className="text-sm">Thanks! Your demo feedback was received.</p>}
      </form>;
    }

    Keep the shared stylesheet imported once. Replace sample image URLs and data with your own. Examples may use layout utilities beyond the precompiled component styles; compile added Tailwind classes in your app or replace them with your own CSS. Customize local source or className, and preserve accessible names and keyboard behavior.

    BUILD WITH IT

    Usage examples

    1 examples

    Try each example, then switch to Code to copy its complete implementation. These catalog snippets use the website's @/components/ui alias; replace it with your local generated path as shown in Quick start.

    01

    Basic Usage

    A complete textarea example. Copy this into a client component.

    Basic Usage

    Loading example…

    THE API

    Props & configuration

    Reference

    Everything you need to fine-tune this component.

    Props and configuration
    PropTypeDefaultDescription
    valuestring—Controlled text value.
    onChangeChangeEventHandler<HTMLTextAreaElement>—Called when text changes.
    rowsnumber—Number of visible text lines.
    maxLengthnumber—Maximum allowed character count.
    disabledbooleanfalseDisables editing.