Label
A lightweight text label for section titles, metadata, and explicit control associations when a full Field layout is not needed.
For complete form fields, prefer Field. It wires the label, control,
description, error message, required/invalid/disabled/read-only state, and ARIA
ids for you. Use standalone Label when you only need the label primitive.
Usage
import { Label } from '@takeoff-ui/react-spar';
<Label as="span">Payment Method</Label>
For native controls, point htmlFor at the control id:
<Label htmlFor="pnr">PNR</Label>
<input id="pnr" />
For Takeoff Input, manual association is possible but Field is usually the
better choice. If you do wire it manually, set the base id on Input and point
htmlFor at the field id generated by Spar (${id}-field):
<Label id="passenger-name-label" htmlFor="passenger-name-field">
Passenger name
</Label>
<Input id="passenger-name">
<Input.Field />
</Input>
Playground
States
required, optional, disabled, readOnly, and invalid are emitted as
data-* attributes on the label for styling. They do not set required,
disabled, readOnly, or aria-invalid on the related control. Set the same
state on the control or use Field when the label and control should stay
synchronized. Required labels render a decorative asterisk after the text.
Label vs Field
Label is intentionally small. If you need helper text, error text, invalid
styling, or shared disabled/read-only/required state, use Field.Label inside
Field. That is the default path for form controls.
API Reference
Label
Props
| Name | Type | Default | Description |
|---|---|---|---|
| children | React.ReactNode | - | Label content. |
| classNames | Partial<Record<"root", string>> | - | Per-slot extra classes. |
| slotProps | Partial<Record<"root", React.HTMLAttributes<HTMLElement>>> | - | Per-slot HTML-attribute overrides. |
| disabled | boolean | false | Marks label for a disabled field (exposed via data attribute for styling) |
| required | boolean | false | Marks label for a required field (exposed via data attribute for styling) |
| readOnly | boolean | false | Marks label for a read-only field (exposed via data attribute for styling) |
| invalid | boolean | false | Marks label for an invalid field (exposed via data attribute for styling) |
| optional | boolean | false | Marks label for an optional field (exposed via data attribute for styling) |
| className | string | - | Appends custom classes to the root slot. |
Data attributes
| Attribute | Applied when | Purpose |
|---|---|---|
| data-slot="root" | Always | Stable selector for wrapper styling on the root slot. |
| data-required | required is true. | Styling hook for required labels. |
| data-optional | optional is true. | Styling hook for optional labels. |
| data-disabled | disabled is true. | Styling hook for disabled labels. |
| data-readonly | readOnly is true. | Styling hook for read-only labels. |
| data-invalid | invalid is true. | Styling hook for invalid labels. |