Popovers

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

<div class="flex flex-wrap items-center justify-center gap-4">
<div id="popover-side-bottom" class="popover">
<button id="popover-side-bottom-trigger" type="button" aria-expanded="false" aria-controls="popover-side-bottom-panel" class="btn" data-variant="outline">Bottom</button>
<div id="popover-side-bottom-panel" data-popover aria-hidden="true" class="w-56">
<header>
<h4>Bottom</h4>
<p>Opens below the button. This is the default.</p>
</header>
</div>
</div>
<div id="popover-side-top" class="popover">
<button id="popover-side-top-trigger" type="button" aria-expanded="false" aria-controls="popover-side-top-panel" class="btn" data-variant="outline">Top</button>
<div id="popover-side-top-panel" data-popover data-side="top" aria-hidden="true" class="w-56">
<header>
<h4>Top</h4>
<p>Opens above the button.</p>
</header>
</div>
</div>
<div id="popover-side-left" class="popover">
<button id="popover-side-left-trigger" type="button" aria-expanded="false" aria-controls="popover-side-left-panel" class="btn" data-variant="outline">Left</button>
<div id="popover-side-left-panel" data-popover data-side="left" aria-hidden="true" class="w-56">
<header>
<h4>Left</h4>
<p>Opens to the left of the button.</p>
</header>
</div>
</div>
<div id="popover-side-right" class="popover">
<button id="popover-side-right-trigger" type="button" aria-expanded="false" aria-controls="popover-side-right-panel" class="btn" data-variant="outline">Right</button>
<div id="popover-side-right-panel" data-popover data-side="right" aria-hidden="true" class="w-56">
<header>
<h4>Right</h4>
<p>Opens to the right of the button.</p>
</header>
</div>
</div>
</div>

Alignment: start, center and end of the button

<div class="flex flex-wrap items-center justify-center gap-4">
<div id="popover-align-start" class="popover">
<button id="popover-align-start-trigger" type="button" aria-expanded="false" aria-controls="popover-align-start-panel" class="btn" data-variant="outline">Start</button>
<div id="popover-align-start-panel" data-popover aria-hidden="true" class="w-56">
<header>
<h4>Start</h4>
<p>Lines up with the start of the button. This is the default.</p>
</header>
</div>
</div>
<div id="popover-align-center" class="popover">
<button id="popover-align-center-trigger" type="button" aria-expanded="false" aria-controls="popover-align-center-panel" class="btn" data-variant="outline">Center</button>
<div id="popover-align-center-panel" data-popover data-align="center" aria-hidden="true" class="w-56">
<header>
<h4>Center</h4>
<p>Centred on the button.</p>
</header>
</div>
</div>
<div id="popover-align-end" class="popover">
<button id="popover-align-end-trigger" type="button" aria-expanded="false" aria-controls="popover-align-end-panel" class="btn" data-variant="outline">End</button>
<div id="popover-align-end-panel" data-popover data-align="end" aria-hidden="true" class="w-56">
<header>
<h4>End</h4>
<p>Lines up with the end of the button.</p>
</header>
</div>
</div>
</div>

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.