Popover

Attaches a floating overlay to any trigger element. Unlike Modal, the rest of the page stays interactive. Supports four placements with automatic flip on collision, cross-axis alignment, click and hover trigger modes, and an optional bordered arrow.

{ Popover } from '/basix/js/popover.js'

Placement

Use placement to set the preferred side. The popover automatically flips to the opposite side if there is not enough viewport space.

Alignment

The align option controls where the popover sits on the cross axis relative to the trigger.

Trigger modes

triggerMode: 'click' (default) toggles on click and closes other open popovers. triggerMode: 'hover' opens on mouseenter with a 120 ms close delay.

Without arrow

Set arrow: false for contextual menus or other content where an arrow would look out of place. Combine with align: 'end' for dropdown-style menus.

Usage

Options

Option Type Default Description
contentstring—HTML string rendered inside the popover.
placementtop | bottom | left | right'bottom'Preferred placement. Flips automatically on collision.
alignstart | center | end'center'Cross-axis alignment relative to the trigger.
offsetnumber8Gap in px between trigger and popover.
arrowbooleantrueShow a bordered arrow pointing at the trigger.
triggerModeclick | hover'click'How the popover is opened.
closeOnOutsideClickbooleantrueClose when clicking outside the popover and trigger.
closeOnEscapebooleantrueClose on Escape key.
classNamestring''Extra CSS class added to the popover element.
onOpen() => void—Callback fired after the popover opens.
onClose() => void—Callback fired after the popover closes.

API

Method / PropertyDescription
open()Opens the popover.
close()Closes the popover.
toggle()Toggles open/close.
destroy()Removes event listeners and closes the popover.
isOpenBoolean — whether the popover is currently open.
Popover.closeAll()Closes all currently open popovers.