Label overview
label[tngLabel] keeps native label semantics while adding predictable data hooks for required and disabled styling. It works equally well with explicit for/id wiring or wrapped controls.
- Native click-to-focus behavior stays on the browser label element.
data-slot,data-required, anddata-disabledare emitted for styling.- You keep full ownership of surrounding field layout, helper copy, and required messaging.
Installation
Import the headless directive when you want to own both markup and styling.
Primitive import
ts
import { TngLabel } from '@tailng-ui/primitives';
Basic usage
Prefer explicit for/id for form fields and wrapped labels for compact checkbox rows.
Explicit association
html
<label tngLabel for="workspace-name">Workspace name</label>
<input id="workspace-name" type="text" />
Wrapped checkbox row
html
<label tngLabel>
<input type="checkbox" />
Send release alerts
</label>
Style variants
The label contract stays the same while your surrounding shell changes between plain CSS and Tailwind utility styling.
Headless label stack (Plain-CSS)
Headless label stack (Tailwind CSS)
Accessibility baseline
- Use
for/idwhen the label and control are separate siblings. - If a label is marked required, keep
aria-requiredor nativerequiredon the control. - Use
disabledon the control itself;data-disabledon the label is only a visual hook.