Search for a command to run...
Renders an accessible label associated with controls.
npx shadcn@latest add @zaidan/labelpnpx shadcn add @zaidan/labelyarn dlx shadcn@latest add @zaidan/labelbunx shadcn@latest add @zaidan/labelCopy and paste the following code into your project.
1/** biome-ignore-all lint/a11y/noLabelWithoutControl: <component file - for/htmlFor handled by consumer> */2import type { ComponentProps } from "solid-js";3import { splitProps } from "solid-js";4import { cn } from "~/lib/utils";5
6type LabelProps = ComponentProps<"label">;7
8const Label = (props: LabelProps) => {9 const [local, others] = splitProps(props, ["class"]);10
11 return (12 <label13 class={cn(14 "z-label flex select-none items-center peer-disabled:cursor-not-allowed group-data-[disabled=true]:pointer-events-none",15 local.class,16 )}17 data-slot="label"18 {...others}19 />20 );21};22
23export { Label };Here are the source code of all the examples from the preview page:
import { Checkbox } from "~/components/ui/checkbox";import { Field } from "~/components/ui/field";import { Label } from "~/components/ui/label";function LabelWithCheckbox() { return ( <Example title="With Checkbox"> <Field orientation="horizontal"> <Checkbox id="label-demo-terms" /> <Label for="label-demo-terms">Accept terms and conditions</Label> </Field> </Example> );}import { Field } from "~/components/ui/field";import { Input } from "~/components/ui/input";import { Label } from "~/components/ui/label";function LabelWithInput() { return ( <Example title="With Input"> <Field> <Label for="label-demo-username">Username</Label> <Input id="label-demo-username" placeholder="Username" /> </Field> </Example> );}import { Field } from "~/components/ui/field";import { Input } from "~/components/ui/input";import { Label } from "~/components/ui/label";function LabelDisabled() { return ( <Example title="Disabled"> <Field data-disabled={true}> <Label for="label-demo-disabled">Disabled</Label> <Input id="label-demo-disabled" placeholder="Disabled" disabled /> </Field> </Example> );}import { Field } from "~/components/ui/field";import { Label } from "~/components/ui/label";import { Textarea } from "~/components/ui/textarea";function LabelWithTextarea() { return ( <Example title="With Textarea"> <Field> <Label for="label-demo-message">Message</Label> <Textarea id="label-demo-message" placeholder="Message" /> </Field> </Example> );}