---
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"]
) %}
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:
A <div class="popover"> which wraps around the entire component and holds it state (e.g. open/close).
A <button> that acts as the trigger to open or close the popover.
A <div data-popover> that holds the content of the popover.
Inside of the <div data-popover> is a <nav role="menu"> that contains a combination of:
<button role="menuitem"> for menu items.
<button role="menuitemcheckbox"> for menu items with checkboxes.
<button role="menuitemradio"> for menu items with radio buttons.
<hr role="separator"> to display a horizontal separator.
<div role="group"> to group options.
<span role="heading"> for group headings.
As with the Popover component, you can set up a few additional options on the <div data-popover> element:
data-side can be set to top, bottom, left, or right to change the side of the popover.
data-align can be set to start, center, or end to change the alignment of the popover.