Actions

Popover

A nonmodal panel anchored to a button, for a small form, setting or detail.

Class nameTypeDescription
popoverplf:popoverComponentWraps the trigger and the panel
popover-contentplf:popover-contentPartThe floating panel
popover-titleplf:popover-titlePartThe panel's heading
popover-descriptionplf:popover-descriptionPartMuted text under the title

Default

A panel without a heading needs aria-label or aria-labelledby; without a name the popover gets no behavior.

JavaScript

Popover needs JavaScript. The Full script (pelatform-ui.min.js) starts every component on page load, with no code of your own; with ESM imports, call init() yourself, as in Installation. For markup you add later, see Dynamic content.

<link rel="stylesheet" href="pelatform-ui.min.css">
<script src="pelatform-ui.min.js" defer></script>
<link rel="stylesheet" href="pelatform-ui.prefixed.min.css">
<script src="pelatform-ui.min.js" defer></script>
Attribute Purpose
data-plf-popover Marks the wrapper
data-plf-popover-trigger Optional: marks the <button>, otherwise the wrapper’s direct child without hidden, or that child’s one button when it is a field, as in the pickers. disabled or aria-disabled="true" keeps it closed
data-plf-popover-content Optional: marks the panel, otherwise the wrapper’s direct child with hidden. Its first heading names it unless it has aria-label or aria-labelledby
data-plf-popover-close A button inside the panel that closes it
data-plf-popover-anchor Optional wrapper around the trigger and companion fields; the panel aligns to it. Without it, a direct child that holds the trigger, such as a picker’s field, is the anchor
data-plf-placement top, right, bottom (default) or left; flips to the opposite side when that has more room, and a left or right panel that fits on neither side opens below or above
data-plf-align start, center (default) or end; start and end follow the text direction
autofocus The control in the panel to focus on opening; otherwise the first one, or the panel
data-plf-side Set by the script on the open panel to the side it opened on
Method Behavior
PLF.Popover.getOrCreateInstance(element) Returns the instance, creating it for valid markup
PLF.Popover.getInstance(element) Returns the instance or null
instance.open() Opens and moves focus into the panel; returns false when already open, canceled or disabled
instance.close() Closes and returns focus to the trigger; returns false when already closed or canceled
instance.toggle() Opens or closes
instance.destroy() Closes without events and removes listeners
Event When
plf:popover:before-open Before opening; cancelable
plf:popover:open After opening
plf:popover:before-close Before closing; cancelable
plf:popover:close After closing

Each event’s detail:

Property Value
instance The Popover instance
reason api, trigger or keyboard
trigger The trigger or close button used, otherwise null
Key Action
Enter, Space On the trigger, opens or closes the panel
Tab, Shift+Tab Move through the panel; leaving it closes the panel, without trapping focus
Escape Closes the panel and returns focus to the trigger; inside a Modal, the next Escape closes the dialog

React

Popover from @pelatform/react renders this wrapper around its parts and opens the panel as the script does; it keeps its own state, or the application sets it with open.

Prop Values Default
placement top, right, bottom, left bottom
align start, center, end center
open true or false, which the application changes in onOpenChange Its own state
defaultOpen true starts open when the application does not set open false
onOpenChange (open, reason), called when the panel opens or closes: trigger (the trigger, PopoverClose or a press outside) or keyboard (Escape, Tab or the focus leaving) None

The parts:

Part Element
PopoverTrigger A button with type="button" and aria-expanded; buttonClass() gives it a look
PopoverContent A div with popover-content and role="dialog", named by its PopoverTitle or an aria-label
PopoverTitle An h3 with popover-title, or another heading with level
PopoverDescription A p with popover-description
PopoverClose A button that closes the panel and returns the focus to the trigger

Other props are the element’s own, className and ref included.

Variable Default
--plf-popover-width 18rem, capped by the viewport
--plf-popover-radius Large radius (8px)
--plf-popover-bg, --plf-popover-color Elevated surface and text
--plf-popover-border Subtle border

Built with Pelatform UIv0.1.0

Components

Getting started

Foundations

Components

Actions

Data display

Navigation

Feedback

Data input

Layout

Advanced

Integrations

Blocks

Application

Authentication

Icons