A Filter chip opening a text filter. The trigger's popovertarget opens and closes the popup without a script, and an outside click or Escape closes it too. anchor-name and position-anchor tie the two together. The popup has no padding: lay out its content yourself, as the style does here. A button inside with popovertargetaction="hide" closes it.
8px below its trigger, aligned to its start, and at least as wide. Without room below it opens above, sliding up instead of down; without room at the end it aligns to the trigger's other edge. Scroll until this button is near the bottom of the window to see it open above.
<Popup> renders its trigger, then the popup holding its children, and connects them: the trigger gets popovertarget, aria-expanded, and an anchor name, and the popup's data-side follows the side it opens on, so it slides away from the trigger. Other props, ref included, are the popup <div>'s.
Prop
Effect
trigger
The element that opens it, such as a <Button> or a <FilterChip>
id
The popup's id; generated when left out. Pass your own to close it from a button inside, with popoverTarget and popoverTargetAction="hide"
HTML
A <div class="hpopup" popover>, opened by a trigger with popovertarget. The trigger's style="anchor-name: --…" matches the popup's style="position-anchor: --…". The popup has no padding, so a panel lays out its own content. Load popup.css.
Hook
Effect
data-side="top"
The popup opened above its trigger, so it slides from below
It needs a script for aria-expanded and data-side. See Popup's full contract.
Accessibility
The browser closes it on outside click and Escape; a popup opened from inside another keeps the outer one open.
Hidden content can't be focused or reached by screen readers.
aria-expanded on the trigger tells screen readers whether it's open.