--- layout: layouts/component.njk title: Dropdown Menu description: Displays a menu to the user — such as a set of actions or functions — triggered by a button. toc: - label: Usage id: usage children: - label: HTML + Javascript id: usage-default - label: Jinja or Nunjucks id: usage-jinja - label: Examples id: examples children: - label: Checkboxes id: example-checkboxes - label: Radio Group id: example-radio-group --- {% from "macros/code_block.njk" import code_block %} {% from "macros/code_preview.njk" import code_preview %} {% from "components/dropdown-menu.njk" import dropdown_menu %} {% set code_html %} {% call dropdown_menu( id="dropdown-menu", trigger="Open", trigger_attrs={"class": "btn-outline"}, content_attrs={"class": "min-w-56"}, register_on=["alpine:init", "htmx:afterSwap"] ) %}
My Account


{% endcall %} {% endset %} {% set code_script %} {% include "components/dropdown-menu-script.njk" %} {% endset %} {{ code_preview("dropdown-menu", code_script | prettyHtml ~ code_html | prettyHtml) }}

Usage

HTML + Javascript

{% lucide "circle-alert" %}

This component requires Javascript.

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. x-bind, x-data, @click).

The component is structured as such:

As with the Popover component, you can set up a few additional options on the <div data-popover> element:

{% from "components/tabs.njk" import tabs %} {% set tabsets = [ { tab: "HTML", panel: code_block(code_html | prettyHtml) }, { tab: "Javascipt (Alpine.js)", panel: code_block(code_script | prettyHtml) } ] %} {{ tabs(id="dropdown-menu", tabsets=tabsets) }}

Jinja or Nunjucks

If you use Jinja (or Nunjucks), you can use the dropdown_menu() macro directly. Read more about using Basecoat with Jinja and Nunjucks.

{% set raw_code %}{% raw %}{% call dropdown_menu( id="dropdown-menu", trigger="Open", trigger_attrs={"class": "btn-outline"}, content_attrs={"class": "min-w-56"}, register_on=["alpine:init", "htmx:afterSwap"] ) %}
My Account


{% endcall %}{% endraw %}{% endset%} {{ code_block(raw_code, "jinja") }}

Examples

Checkboxes

{% set code %}{% call dropdown_menu( id="dropdown-menu-checkboxes", trigger="Open", trigger_attrs={"class": "btn-outline"}, content_attrs={"class": "min-w-56"}, register_on=["alpine:init", "htmx:afterSwap"] ) %}
Account Options

Appearance

{% endcall %}{% endset %} {{ code_preview("dropdown-menu-checkboxes", code | prettyHtml) }}

Radio Group

{% set code %}{% call dropdown_menu( id="dropdown-menu-radio-group", trigger="Open", trigger_attrs={"class": "btn-outline"}, content_attrs={"class": "min-w-56"}, register_on=["alpine:init", "htmx:afterSwap"] ) %}
Panel Position
{% endcall %}{% endset %} {{ code_preview("dropdown-menu", code | prettyHtml) }}