Popover
Dimensions
Set the dimensions for the layer.
<button class="btn btn-outline" popovertarget="demo-popover">Open popover</button>
<div class="popover" id="demo-popover" popover data-pk-placement="bottom"> <div class="popover-header"> <h4 class="popover-title">Dimensions</h4> <p class="popover-description">Set the dimensions for the layer.</p> </div>
<div class="field-group"> <div class="field" data-orientation="horizontal"> <label class="label" for="popover-width">Width</label> <input class="input input-sm" id="popover-width" value="100%" style="width: 8rem" /> </div> <div class="field" data-orientation="horizontal"> <label class="label" for="popover-max-width">Max. width</label> <input class="input input-sm" id="popover-max-width" value="300px" style="width: 8rem" /> </div> <div class="field" data-orientation="horizontal"> <label class="label" for="popover-height">Height</label> <input class="input input-sm" id="popover-height" value="25px" style="width: 8rem" /> </div> </div></div><button class="btn btn-outline" popovertarget="dimensions">Open popover</button>
<div class="popover" id="dimensions" popover data-pk-placement="bottom"> <div class="popover-header"> <h4 class="popover-title">Dimensions</h4> <p class="popover-description">Set the dimensions for the layer.</p> </div> …</div>popovertarget is a browser attribute: it opens the panel, closes it on a second click, closes it
when you click away, and closes it on Escape. partialkit adds the placement, the ARIA wiring and
the focus move.
| Class | Part |
|---|---|
.popover | The panel |
.popover-header | Title and description together |
.popover-title | Names the panel, and labels it for screen readers |
.popover-description | Supporting line |
| Attribute | Meaning |
|---|---|
data-pk-placement | A side — top, bottom, left, right — optionally with -start or -end. Defaults to bottom-start |
data-pk-offset | Distance from the trigger, in pixels |
data-pk-align-offset | Nudge along the other axis, in pixels |
data-pk-anchor | Selector for the element to measure against, when it is not the trigger |
Placement
Section titled “Placement”The panel flips to the other side when there is no room, and never leaves the viewport.
Opens above the trigger.
Opens at the leading edge.
Opens at the trailing edge.
<button class="btn btn-outline" popovertarget="popover-top">Top</button><div class="popover" id="popover-top" popover data-pk-placement="top" style="width: 12rem"> <p class="popover-description">Opens above the trigger.</p></div>
<button class="btn btn-outline" popovertarget="popover-start">Start</button><div class="popover" id="popover-start" popover data-pk-placement="left" style="width: 12rem"> <p class="popover-description">Opens at the leading edge.</p></div>
<button class="btn btn-outline" popovertarget="popover-end">End</button><div class="popover" id="popover-end" popover data-pk-placement="right" style="width: 12rem"> <p class="popover-description">Opens at the trailing edge.</p></div>With a form
Section titled “With a form”Share this document
Anyone with the link can view it.
<button class="btn btn-outline" popovertarget="popover-form">Share</button>
<div class="popover" id="popover-form" popover data-pk-placement="bottom" style="width: 20rem"> <div class="popover-header"> <h4 class="popover-title">Share this document</h4> <p class="popover-description">Anyone with the link can view it.</p> </div>
<div class="input-group"> <input class="input input-group-control" id="popover-link" value="partialkit.dev/docs" readonly /> <span class="input-group-addon" data-align="inline-end"> <button class="btn btn-ghost btn-icon-sm" type="button"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> <rect width="14" height="14" x="8" y="8" rx="2"></rect> <path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"></path> </svg> <span class="sr-only">Copy link</span> </button> </span> </div></div>Popover or Dropdown Menu?
Section titled “Popover or Dropdown Menu?”A popover holds content: fields, text, anything you can tab through. A dropdown menu holds commands, navigated with the arrow keys and closed by choosing one. If a user needs to type into it, it is a popover.
Set dir="rtl" on the page or on any subtree — left and right are read in reading
order, so they swap sides. See the button page for a live example.
Accessibility
Section titled “Accessibility”- The panel is a
dialogrole, not amenu. Content is read and tabbed through; commands are not. .popover-titlelabels the panel automatically througharia-labelledby, so it is announced by name when it opens. Without a title, give the panel anaria-label.- Focus moves in and comes back. The first control inside receives focus; when the panel closes, focus returns to the trigger — including after a click outside, which browsers do not all handle themselves.
- Escape closes it, which the browser provides for any element with
popover. - Tab does not trap. A popover is not modal: tabbing past the last control leaves the panel, which is the behaviour people expect from a non-blocking surface.