Popovers
<div id="demo-popover" class="popover">
<button id="demo-popover-trigger" type="button" aria-expanded="false" aria-controls="demo-popover-popover" class="btn" data-variant="outline">Open popover</button>
<div id="demo-popover-popover" data-popover aria-hidden="true" class="w-72">
<header>
<h4>Dimensions</h4>
<p>Set the dimensions for the layer.</p>
</header>
<form class="grid gap-2" onsubmit="event.preventDefault()">
<div class="grid grid-cols-3 items-center gap-4">
<label class="label" for="demo-popover-width">Width</label>
<input type="text" id="demo-popover-width" value="100%" class="input col-span-2 h-8" autofocus />
</div>
<div class="grid grid-cols-3 items-center gap-4">
<label class="label" for="demo-popover-max-width">Max. width</label>
<input type="text" id="demo-popover-max-width" value="300px" class="input col-span-2 h-8" />
</div>
<div class="grid grid-cols-3 items-center gap-4">
<label class="label" for="demo-popover-height">Height</label>
<input type="text" id="demo-popover-height" value="25px" class="input col-span-2 h-8" />
</div>
<div class="grid grid-cols-3 items-center gap-4">
<label class="label" for="demo-popover-max-height">Max. height</label>
<input type="text" id="demo-popover-max-height" value="none" class="input col-span-2 h-8" />
</div>
</form>
</div>
</div>
Side: below, above, left and right of the button
Alignment: start, center and end of the button
Side and alignment together
<div class="flex flex-wrap items-center justify-center gap-4">
<div id="popover-corner-top-end" class="popover">
<button id="popover-corner-top-end-trigger" type="button" aria-expanded="false" aria-controls="popover-corner-top-end-panel" class="btn" data-variant="outline">Top, end</button>
<div id="popover-corner-top-end-panel" data-popover data-side="top" data-align="end" aria-hidden="true" class="w-56">
<header>
<h4>Top, end</h4>
<p>Above the button, lined up with its end.</p>
</header>
</div>
</div>
<div id="popover-corner-right-center" class="popover">
<button id="popover-corner-right-center-trigger" type="button" aria-expanded="false" aria-controls="popover-corner-right-center-panel" class="btn" data-variant="outline">Right, center</button>
<div id="popover-corner-right-center-panel" data-popover data-side="right" data-align="center" aria-hidden="true" class="w-56">
<header>
<h4>Right, center</h4>
<p>Right of the button, centred on it.</p>
</header>
</div>
</div>
</div>
A header with a count: a badge after the title puts them on one row
<div id="demo-popover-count" class="popover">
<button id="demo-popover-count-trigger" type="button" aria-expanded="false" aria-controls="demo-popover-count-popover" class="btn" data-variant="outline">Products<i class="icon icon-chevron-down" aria-hidden="true"></i></button>
<div id="demo-popover-count-popover" data-popover aria-hidden="true" class="w-72">
<header>
<h4>Products</h4>
<span class="badge" data-variant="secondary">3</span>
</header>
<ul class="flex flex-col gap-3">
<li class="flex items-center gap-3"><span class="avatar"><img src="/demo-assets/products/watch.jpg" alt="" /></span><span class="flex-1">Timeless Watch</span><span class="tabular-nums">$59.99</span></li>
<li class="flex items-center gap-3"><span class="avatar"><img src="/demo-assets/products/mug.jpg" alt="" /></span><span class="flex-1">Ceramic Mug</span><span class="tabular-nums">$49.99</span></li>
<li class="flex items-center gap-3"><span class="avatar"><img src="/demo-assets/products/stool.jpg" alt="" /></span><span class="flex-1">Wooden Stool</span><span class="tabular-nums">$49.99</span></li>
</ul>
</div>
</div>
API Reference
Attributes
| Attribute | On | Values | Default | Description |
|---|---|---|---|---|
| data-side | the [data-popover] panel | "bottom", "top", "left", "right", "inline-start", "inline-end" | "bottom" | The side of the button the panel opens on. Below and above swap when the panel does not fit and the other side has more room. |
| data-align | the [data-popover] panel | "start", "center", "end" | "start" | How the panel lines up with the button. |
| autofocus | an element in the panel | present or absent | absent | The element that takes focus when the panel opens. |
| aria-hidden | the [data-popover] panel | "true", "false" | set by the script | "false" while the panel is open. |
| aria-expanded | the button | "true", "false" | set by the script | "true" while the panel is open. |
Methods and properties
| Member | Type | Description |
|---|---|---|
| open() | method | Opens the panel. Any other open panel closes. |
| close() | method | Closes the panel. Focus that was inside it goes back to the button. |
Events
| Event | On | Detail | Description |
|---|---|---|---|
| tsugi:popover | document | { source } | Sent as any panel opens: a popover's, a dropdown's, a select's or a date picker's. source is the element that owns the panel. |
Keyboard
| Key | Description |
|---|---|
| Enter or Space | On the button: opens or closes the panel. |
| Escape | Closes the panel only. A dialog or drawer around it stays open. |
| Tab | Past the last control in the panel: closes it. |
A click outside the popover closes it.
Once the script has started it, the element carries data-popover-initialized="true" and sends tsugi:initialized. The methods and properties above are on the element itself.


