SutraUI.Label (Sutra UI v0.2.0)
View SourceRenders an accessible label for form controls.
Labels are essential for form accessibility, providing a text description
that is programmatically associated with form controls. When properly linked
via the for attribute, clicking the label will focus the associated input.
Examples
# Basic label with for attribute
<.label for="email">Email address</.label>
<.input id="email" name="email" type="email" />
# Label with custom styling
<.label for="terms" class="font-bold">Accept Terms</.label>
# Required field indicator (styled via CSS)
<.label for="name" class="required">Full Name</.label>
# Label with additional attributes
<.label for="phone" id="phone-label">Phone Number</.label>Accessibility
- Always use the
forattribute to associate labels with their form controls - The
forvalue must match theidof the associated input element - Clicking a properly associated label will focus/activate its form control
- Screen readers announce the label text when the user focuses the input
- Avoid using placeholder text as a substitute for labels
- For required fields, consider adding visual indicators and
aria-requiredon the input rather than relying solely on the label text
Summary
Functions
Renders a label element.
Functions
Renders a label element.
Examples
<.label for="email">Email address</.label>
<.label for="terms" class="font-bold">Terms</.label>Attributes
for(:string) - The id of the form element this label is for. Defaults tonil.class(:string) - Additional CSS classes. Defaults tonil.- Global attributes are accepted. Additional HTML attributes.
Slots
inner_block(required) - The label content.