<p>If you use a <code><select></code> element, just add the <code>select</code> class to it or have a parent with the <code>form</code> class (<a href="/components/form">read more about form</a>).</p>
<p>You will need to include the Javascript (Alpine.js) code provided below before the HTML code for this component. As with all interactive components, you will need to add some Alpine.js properties to certain elements (e.g. <code class="text-xs">x-bind</code>, <code class="text-xs">x-data</code>, <code class="text-xs">@click</code>).</p>
<p>If you need to do more than what <code><select></code> allows (e.g. HTML options), you can use this component. It is structured as such:</p>
<ul>
<li>A <code><div class="popover"></code> which wraps around the entire component and holds it state (e.g. open/close).</li>
<li>A <code><button></code> that acts as the trigger to open or close the popover.</li>
<li>A <code><div data-popover></code> that holds the content of the popover.</li>
<li>Inside of the <code><div data-popover></code> is a <code><nav role="listbox"></code> that contains a combination of:
<ul>
<li><code><div role="option"></code> for the options with a <code>data-value</code> attribute.</li>
<li><code><hr role="separator"></code> to display a horizontal separator.</li>
<li><code><div role="group"></code> to group options.</li>
<li><code><span role="heading"></code> for group headings.</li>
</ul>
</li>
<li>An <code><input type="hidden"></code> to hold the value of the field (if needed).</li>
</ul>
<p>As with the <a href="/components/popover">Popover</a> component, you can set up a few additional options on the <code><div data-popover></code> element:</p>
<ul>
<li><code>data-side</code> can be set to <code>top</code>, <code>bottom</code>, <code>left</code>, or <code>right</code> to change the side of the popover.</li>
<li><code>data-align</code> can be set to <code>start</code>, <code>center</code>, or <code>end</code> to change the alignment of the popover.</li>
<p class="prose">If you use Jinja (or Nunjucks), you can use the <code>dropdown_menu()</code> macro directly. <a href="/installation/#install-macros">Read more about using Basecoat with Jinja and Nunjucks</a>.</p>