--- layout: layouts/page.njk title: Popover description: Displays rich content in a portal, triggered by a button. toc: - label: Usage id: usage children: - label: HTML + JavaScript id: usage-html-js children: - label: "Step 1 (Optional): Include the JavaScript file" id: usage-html-js-1 - label: "Step 2: Add your popover HTML" id: usage-html-js-2 - label: HTML structure id: usage-html-js-3 - label: Jinja and Nunjucks id: usage-macro --- {% from "macros/code_preview.njk" import code_preview %} {% from "macros/code_block.njk" import code_block %} {% from "popover.njk" import popover %} {% set code_html %} {% call popover( id="demo-popover", trigger="Open popover", trigger_attrs={"class": "btn-outline"}, popover_attrs={"class": "w-80"} ) %}

Dimensions

Set the dimensions for the layer.

{% endcall %} {% endset %} {{ code_preview("popover", code_html | prettyHtml) }}

Usage

HTML + JavaScript

Step 1: Include the JavaScript file

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:

{% set code_script %}{% endset %} {{ code_block(code_script | prettyHtml, "html") }}
Components with JavaScript {% lucide "arrow-right" %} Use the CLI {% lucide "arrow-right" %}

Step 2: Add your popover HTML

{{ code_block(code_html | prettyHtml, "html") }}

HTML structure

<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-expanded="false": tracks the popover's state.
  • onclick: a simple function to update aria-expanded.
<div popover class="popover" id="{ POPOVER_ID }">
As with the Popover component, you can set up the side and alignment of the popover using the data-side and data-align attributes.

Jinja and Nunjucks

You can use the popover() Nunjucks or Jinja macro for this component.

Use Nunjucks or Jinja macros {% lucide "arrow-right" %} Jinja macro {% lucide "arrow-right" %} Nunjucks macro {% lucide "arrow-right" %}
{% set raw_code %}{% raw %}{% call popover( id="demo-popover", trigger="Open popover", trigger_attrs={"class": "btn-outline"}, popover_attrs={"class": "w-80 p-4"} ) %}

Dimensions

Set the dimensions for the layer.

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