Components / Label
Label
A visible name for a form control. Square, monospaced typography with native HTML association: click the label to focus its input.
Storybook runs locally or as a separately hosted build; no hosted Storybook is configured. Source and setup links match the install revision.
Usage
Give the control a unique id and pass that id to htmlFor. Try clicking the label, then type in the input or reach it with Tab. This small native example needs no artificial state controls.
'use client';
import { useId } from 'react';
import { Label } from '@/components/ui/yads-label';
const fieldClass = 'grid gap-2 w-full max-w-sm';
Installation
pnpm dlx [email protected] add biehlio/yet-another-design-system/label#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40Documentation samples use basic Tailwind utilities for layout. Install each YADS component imported by the sample.
Run this revision-pinned command in a project configured for shadcn. It installs yads-label.tsx, its scoped stylesheet and JetBrains Mono. Import { Label } from @/components/ui/yads-label (adjust your alias). No separate theme install, Tailwind or Radix dependency is needed. Add a dark class to an ancestor for dark typography.
Copy sample includes each complete React module, native input styles and any recipe CSS, even while collapsed. Interactive examples use a client boundary in React Server Component apps.
Required and helper text
The visible “(required)” instruction is paired with native required on the input. Helper text belongs to the control through aria-describedby, not to Label. A label alone does not validate a field.
We only use this address for account updates.
'use client';
import { useId } from 'react';
import { Label } from '@/components/ui/yads-label';
const fieldClass = 'grid gap-2 w-full max-w-sm';
Customization
Use className for layout and emphasis without changing the control association. This recipe keeps the inherited light/dark color; basic Tailwind utilities arrange the field. Inline style can also override typography or color.
'use client';
import { useId } from 'react';
import { Label } from '@/components/ui/yads-label';
const fieldClass = 'grid gap-2 w-full max-w-sm';
Accessibility
- Use visible, descriptive text. Match htmlFor to one labelable control’s unique id; useId avoids collisions when examples repeat. Placeholder text is not a label.
- The control receives keyboard focus and input; Label is not a button or an extra tab stop. Preserve the control’s focus ring. Do not put unrelated links or action buttons inside a label.
- Put required, disabled, aria-invalid and aria-describedby on the control as appropriate. Label has no disabled, checked or loading API. A disabled input stays disabled when its label is clicked.
- This component intentionally uses native label rather than Radix Label: HTML already supplies naming and click-to-focus for native inputs. Native props and ref are preserved without an additional primitive dependency. It does not implement Radix-specific mouse-selection suppression or an asChild API.
API reference
Label renders one native <label>. It accepts React.ComponentPropsWithoutRef<'label'> and forwards its ref as HTMLLabelElement. No required custom props or state defaults.
| Prop | Type / default | Purpose |
|---|---|---|
| htmlFor | string / unset | Associates the label with a control id. |
| children | ReactNode / unset | The visible control name. |
| className, style | string, CSSProperties / unset | Additional styles; className is merged with the scoped label class. |
| ref | Ref<HTMLLabelElement> / unset | Access to the rendered label. |
| Native attributes | Native label props / unchanged | id, title, data-*, aria-* and event handlers are forwarded. |