Label
A label component that can be associated with form inputs using the for attribute.
Examples
Default
<div class="flex items-center gap-2">
<c-checkbox id="terms"></c-checkbox>
<c-label label-for="terms">Accept terms and conditions</c-label>
</div>
With Radio Group
<c-radio-group value="option-1" radio-group-classes="flex flex-col gap-3">
<div class="flex items-center gap-2">
<c-radio-group-item id="option-1" value="option-1"></c-radio-group-item>
<c-label label-for="option-1">Option 1</c-label>
</div>
<div class="flex items-center gap-2">
<c-radio-group-item id="option-2" value="option-2"></c-radio-group-item>
<c-label label-for="option-2">Option 2</c-label>
</div>
<div class="flex items-center gap-2">
<c-radio-group-item id="option-3" value="option-3"></c-radio-group-item>
<c-label label-for="option-3">Option 3</c-label>
</div>
</c-radio-group>
With Text Input
<div class="flex flex-col gap-2">
<c-label label-for="email">Email address</c-label>
<c-input id="email" type="email" placeholder="you@example.com"></c-input>
</div>
API Reference
Label
A label component that provides accessible labeling for form inputs and can toggle checkboxes/radio buttons when clicked.
Features
- Accessible: Uses semantic
<label>element for proper form accessibility - Interactive: Clicking the label toggles checkboxes/radio buttons or focuses text inputs
- Customizable: Accepts additional classes via
label-classesprop - Peer-aware: Includes
peer-disabled:variants for styling based on associated input state - Mobile support: Uses both
clickandtouchendso label taps work on mobile browsers whereclickmay not fire
Implementation Notes
Label activation uses a message bus (not native label[for]) so it works across Shadow DOM boundaries (e.g. Salesforce LWR, nested components). Form controls subscribe to LABEL_ACTIVATE and match by id. A 300ms debounce prevents double-firing when both touchend and click fire on the same tap.