--- layout: layouts/page.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-html-js children: - label: "Step 1: Include the JavaScript files" id: usage-html-js-1 - label: "Step 2: Add your dropdown menu HTML" id: usage-html-js-2 - label: HTML structure id: usage-html-js-3 - label: JavaScript events id: usage-html-js-4 - label: Jinja and Nunjucks id: usage-macro - 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 "dropdown-menu.njk" import dropdown_menu %} {% set code_html %} {% call dropdown_menu( id="demo-dropdown-menu", trigger="Open", trigger_attrs={"class": "btn-outline"}, popover_attrs={"class": "min-w-56"} ) %}
You can either include the JavaScript file for all the components, or just the one for this component by adding this to the <head> of your page:
<div class="dropdown-menu"><button type="button" popovertarget="{ POPOVER_ID }">The trigger to open the popover, can also have the following attributes:
id="{BUTTON_ID}": linked to by the aria-labelledby attribute of the listbox.aria-haspopup="menu": indicates that the button opens a menu.aria-controls="{ MENU_ID }": points to the menu's id.aria-expanded="false": tracks the popover's state.<div popover class="popover" id="{ POPOVER_ID }">data-side and data-align attributes.
<div role="menu">id="{ MENU_ID }": refered to by the aria-controls attribute of the trigger.aria-labelledby="{ BUTTON_ID }": linked to by the button's id attribute.<button role="menuitem"><button role="menuitemcheckbox"><button role="menuitemradio"><hr role="separator"> Optional<div role="group"> Optionalaria-labelledby attribute to link to a heading.<span role="heading">id attribute if you use the aria-labelledby attribute on the group.basecoat:initializedbasecoat:initialized event on itself.basecoat:popoverbasecoat:popover event on document. Other popover components (Combobox, Dropdown Menu, Popover and Select) listen for this to close any open popovers.You can use the dropdown_menu() Nunjucks or Jinja macro for this component.