Label

The Label component is used to provide a descriptive label for form fields. It is built on top of React Aria to ensure accessibility.

Installation

Install the component using the Tailgrids CLI.

npx @tailgrids/cli add label

Anatomy

Import the component and pass the required props.

import { Label } from "@/registry/core/label";

export const LabelExample = () => <Label htmlFor="input-id">Label Text</Label>;

Examples

With Text Area

Use the Label component with a description-heavy field like TextArea.

With Select

Associate the Label with a NativeSelect component.

API Reference

Label

PropTypeDefaultDescription
classNamestring-Additional CSS classes to apply to the label.
childrenReactNode-The content to be displayed within the label.

Note: Label also inherits all props from react-aria-components's LabelProps.

Accessibility

  • Semantic HTML: The component renders a <label> element.
  • Form Association: Use the htmlFor prop to link the label to a form control's id. This ensures that clicking the label focuses the control and screen readers announce the label correctly.
  • Support for React Aria: Since it extends React Aria's Label, it integrates seamlessly with other React Aria components and hooks for advanced accessibility patterns.