textarea-demo
import { Textarea } from "@/components/ui/textarea"
export function TextareaDemo() {
return <Textarea placeholder="Type your message here." />
}
pnpm dlx shadcn@latest add "https://ui.dalim.in/r/textarea-demo.json"
Installation
pnpm dlx shadcn@latest add textarea
Usage
import { Textarea } from "@/components/ui/textarea"
<Textarea />
Examples
Default
textarea-demo
import { Textarea } from "@/components/ui/textarea"
export function TextareaDemo() {
return <Textarea placeholder="Type your message here." />
}
pnpm dlx shadcn@latest add "https://ui.dalim.in/r/textarea-demo.json"
Disabled
textarea-disabled
import { Textarea } from "@/components/ui/textarea"
export function TextareaDisabled() {
return <Textarea placeholder="Type your message here." disabled />
}
pnpm dlx shadcn@latest add "https://ui.dalim.in/r/textarea-disabled.json"
With Label
textarea-with-label
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
export function TextareaWithLabel() {
return (
<div className="grid w-full gap-3">
<Label htmlFor="message">Your message</Label>
<Textarea placeholder="Type your message here." id="message" />
</div>
)
}
pnpm dlx shadcn@latest add "https://ui.dalim.in/r/textarea-with-label.json"
With Text
textarea-with-text
Your message will be copied to the support team.
import { Label } from "@/components/ui/label"
import { Textarea } from "@/components/ui/textarea"
export function TextareaWithText() {
return (
<div className="grid w-full gap-3">
<Label htmlFor="message-2">Your Message</Label>
<Textarea placeholder="Type your message here." id="message-2" />
<p className="text-muted-foreground text-sm">
Your message will be copied to the support team.
</p>
</div>
)
}
pnpm dlx shadcn@latest add "https://ui.dalim.in/r/textarea-with-text.json"
With Button
textarea-with-button
import { Button } from "@/components/ui/button"
import { Textarea } from "@/components/ui/textarea"
export function TextareaWithButton() {
return (
<div className="grid w-full gap-2">
<Textarea placeholder="Type your message here." />
<Button>Send message</Button>
</div>
)
}
pnpm dlx shadcn@latest add "https://ui.dalim.in/r/textarea-with-button.json"
Form
textarea-form
"use client"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
import { toast } from "sonner"
import { z } from "zod"
import { Button } from "@/components/ui/button"
import {
Form,
FormControl,
FormDescription,
FormField,
FormItem,
FormLabel,
FormMessage,
} from "@/components/ui/form"
import { Textarea } from "@/components/ui/textarea"
const FormSchema = z.object({
bio: z
.string()
.min(10, {
message: "Bio must be at least 10 characters.",
})
.max(160, {
message: "Bio must not be longer than 30 characters.",
}),
})
export function TextareaForm() {
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
})
function onSubmit(data: z.infer<typeof FormSchema>) {
toast("You submitted the following values", {
description: (
<pre className="mt-2 w-[320px] rounded-md bg-neutral-950 p-4">
<code className="text-white">{JSON.stringify(data, null, 2)}</code>
</pre>
),
})
}
return (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="w-2/3 space-y-6">
<FormField
control={form.control}
name="bio"
render={({ field }) => (
<FormItem>
<FormLabel>Bio</FormLabel>
<FormControl>
<Textarea
placeholder="Tell us a little bit about yourself"
className="resize-none"
{...field}
/>
</FormControl>
<FormDescription>
You can <span>@mention</span> other users and organizations.
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<Button type="submit">Submit</Button>
</form>
</Form>
)
}
pnpm dlx shadcn@latest add "https://ui.dalim.in/r/textarea-form.json"