@zedtech/zedkit-ui
Label a form control
Accessible labels that pair with any control via `htmlFor`.
alpha
pnpm import label.tsx
Simple Required mark
Install
pnpm add @zedtech/zedkit-uiPackage version: 0.4.0 (changesets).
Import
import { Label, LabelProps } from "@zedtech/zedkit-ui";Registry source
Copy into your app after npx shadcn add (imports are rewritten for consumers).
// Derived from shadcn/ui (label) — see Provenance in packages/ui/README.md. Tolerated exception: migrated to custom code only when customization needs it.
"use client";
import * as React from "react";
import * as LabelPrimitive from "@radix-ui/react-label";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
const labelVariants = cva(
"text-sm leading-none font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
);
type LabelProps = React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
VariantProps<typeof labelVariants>;
const Label = React.forwardRef<React.ElementRef<typeof LabelPrimitive.Root>, LabelProps>(({ className, ...props }, ref) => (
<LabelPrimitive.Root ref={ref} className={cn(labelVariants(), className)} {...props} />
));
Label.displayName = LabelPrimitive.Root.displayName;
export { Label, type LabelProps };
Exports
| Symbol | Role |
|---|---|
| Label | Component |
| LabelProps | Props type |
Wraps: `@radix-ui/react-label`
Preview
Examples
import { Input, Label } from "@zedtech/zedkit-ui";
<Label htmlFor="name">Name</Label>
<Input id="name" placeholder="Ada" />import { Input, Label } from "@zedtech/zedkit-ui";
<Label htmlFor="email">Email <span aria-hidden="true">*</span></Label>
<Input id="email" required />Props
Prop
Type
Accessibility
Pairs with a control via `htmlFor` plus a matching `id`; clicking the label focuses the control (native behavior). A disabled peer dims the label via `peer-disabled`.
Related
Troubleshooting
Clicking the label does nothing — the control needs a matching `id` for `htmlFor`. Label not dimming with a disabled control — `peer-disabled` needs the control as a preceding `peer` sibling.