Label
Renders an accessible label associated with controls.
Loading...
<div class="flex gap-2">
<twig:Checkbox id="terms" />
<twig:Label for="terms">Accept terms and conditions</twig:Label>
</div>
Installation
bin/console ux:install label --kit shadcn
That's it!
Install the following Composer dependencies:
composer require tales-from-a-dev/twig-tailwind-extra:^1.0.0
Copy the following file(s) into your Symfony app:
templates/components/Label.html.twig
{# @block content The label text for a form control #}
<label
data-slot="label"
class="{{ ('flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50 ' ~ attributes.render('class'))|tailwind_merge }}"
{{ attributes.without('class') }}
>
{%- block content %}{% endblock -%}
</label>
Happy coding!
Usage
<twig:Label for="email">Your email address</twig:Label>
Examples
Label in Field
For form fields, use the Field component which includes built-in label, description, and error handling.
Loading...
<div class="w-full max-w-md">
<twig:Field>
<twig:Field:Label for="email">Your email address</twig:Field:Label>
<twig:Input id="email" />
</twig:Field>
</div>
RTL
To enable RTL support, set the dir="rtl" attribute on the root element.
Loading...
<div class="flex flex-col gap-8">
{# Arabic #}
<div class="flex gap-2" dir="rtl">
<twig:Checkbox id="terms-ar" />
<twig:Label for="terms-ar">قبول الشروط والأحكام</twig:Label>
</div>
{# Hebrew #}
<div class="flex gap-2" dir="rtl">
<twig:Checkbox id="terms-he" />
<twig:Label for="terms-he">קבל תנאים והגבלות</twig:Label>
</div>
</div>
API Reference
Component Label
| Block | Description |
|---|---|
content |
The label text for a form control |