Select
A dropdown control that allows users to choose from a list of options.
Loading...
<twig:Select class="max-w-sm">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</twig:Select>
Installation
Ensure the Symfony UX Toolkit is installed in your Symfony app:
composer require --dev symfony/ux-toolkit
Then, install the recipe and its dependencies by running:
bin/console ux:install Select --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:
{# @block content The default block #}
<select
class="{{ 'flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1 ' ~ attributes.render('class')|tailwind_merge }}"
{{ attributes }}
>
{%- block content %}{% endblock -%}
</select>
Happy coding!
Usage
<twig:Select class="max-w-sm">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</twig:Select>
Examples
Default
Loading...
<twig:Select class="max-w-sm">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</twig:Select>
With Label
Loading...
<div class="grid w-full max-w-sm items-center gap-1.5">
<twig:Label for="framework">Framework</twig:Label>
<twig:Select id="framework">
<option value="symfony">Symfony</option>
<option value="laravel">Laravel</option>
<option value="tempest">Tempest</option>
</twig:Select>
</div>
Disabled
Loading...
<twig:Select disabled class="max-w-sm">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</twig:Select>
API Reference
Select
| Block | Description |
|---|---|
content |
The default block |