Presets

Blocks

Get PRO

Need premium blocks and templates? Upgrade to PRO and get access.

Upgrade
JoinLogin
Presets
Monochrome
Overview
  • Introduction
  • Components
  • Installation
Components
  • Accordion
  • Alert
  • Alert Dialog
  • Aspect Ratio
  • Avatar
  • Badge
  • Breadcrumb
  • Button
  • Button Group
  • CalendarNEW
  • Card
  • CarouselNEW
  • Checkbox
  • Collapsible
  • Dialog
  • Dropdown Menu
  • Empty
  • Field
  • Input
  • Input Group
  • Item
  • Kbd
  • Label
  • Native Select
  • Scroll Area
  • SelectNEW
  • Separator
  • SwitchNEW
  • Table
  • Tabs
  • Textarea
  • TooltipNEW

Textarea

PreviousNext

Displays a form textarea or a component that looks like a textarea.

1import { Textarea } from "@/components/ui/textarea";23export default function Preview() {4  return <Textarea className="max-w-sm" placeholder="Type your message here." />;

Installation

pnpm dlx sprawlify@latest add textarea
npx sprawlify@latest add textarea
yarn sprawlify@latest add textarea
bunx --bun sprawlify@latest add textarea

Install the following dependencies:

pnpm add @sprawlify/primitives @sprawlify/react
npm install @sprawlify/primitives @sprawlify/react
yarn add @sprawlify/primitives @sprawlify/react
bun add @sprawlify/primitives @sprawlify/react

Add the following files to your project:

textarea.tsx
1"use client";23import * as React from "react";4import { cn } from "@/lib/utils";5import { sprawlify } from "@sprawlify/react";67function Textarea({ className, ...props }: React.ComponentProps<typeof sprawlify.textarea>) {8  return (9    <sprawlify.textarea10      data-scope="textarea"11      data-part="root"12      data-slot="textarea"13      className={cn(14        "border-input dark:bg-input/30 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 disabled:bg-input/50 dark:disabled:bg-input/80 rounded-lg border bg-input/30 px-2.5 py-2 text-base transition-colors focus-visible:ring-3 aria-invalid:ring-3 md:text-sm placeholder:text-muted-foreground flex field-sizing-content min-h-16 w-full outline-none disabled:cursor-not-allowed disabled:opacity-50",15        className,16      )}17      {...props}18    />19  );20}2122export { Textarea };23

Update the import paths to match your project setup.

Usage

1import { Textarea } from "@/components/ui/textarea"
1<Textarea />

Examples

Button

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

1import { Button } from "@/components/ui/button";2import { Textarea } from "@/components/ui/textarea";34export default function Preview() {

Disabled

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

1import { Field, FieldLabel } from "@/components/ui/field";2import { Textarea } from "@/components/ui/textarea";34export default function Preview() {

Field

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

1import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";2import { Textarea } from "@/components/ui/textarea";34export default function Preview() {

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.

1import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";2import { Textarea } from "@/components/ui/textarea";34export default function Preview() {

On This Page

InstallationUsageExamplesButtonDisabledFieldInvalid

Get PRO

Need premium blocks and templates? Upgrade to PRO and get access.