Usage

Set for to the id of the element that opens the popover. The trigger and the popover must be in the same document or shadow root. The popover sets aria-haspopup and aria-expanded on its trigger.

For a list of actions, use orb-menu instead. It handles the keyboard and focus the way menus need.

show() opens the popover at a pointer event, or at any object with getBoundingClientRect, such as a Range at a caret. Set contextElement on that object to the scrolling element that contains it, so the popover follows the scroll. Without for, the popover has no trigger, so a press outside it or Escape closes it.

Open Popover
<orb-button id="popover-trigger">Open Popover</orb-button>
<orb-popover for="popover-trigger">
  <input autofocus/>
</orb-popover>

Manual test:

  • Click the button. The popover opens next to it. Click the button again, click outside, or press Escape to close it.
  • After Escape, focus returns to the button.

Properties

arrow

Description Renders an arrow pointing to the trigger
Attribute arrow
Type boolean
Default true

arrowPadding

Description The padding between the arrow and the edges of the popover. Useful if you change the border-radius of the popover
Attribute arrow-padding
Type number
Default 6

destroy

Description Execute a callback after the popover has dismissed
Attribute –
Type () => void | Promise<void>
Default undefined

for

Description Id of the element that will trigger the popover to open
Attribute for
Type string
Default undefined

init

Description Execute a callback before the popover starts presenting
Attribute –
Type () => void | Promise<void>
Default undefined

offsetX

Description Horizontal offset used when auto positioning the popover content
Attribute offset-x
Type number
Default 0

offsetY

Description Vertical offset used when auto positioning the popover content
Attribute offset-y
Type number
Default 10

placement

Description Where the popover should be placed
Attribute placement
Type "bottom" | "bottom-end" | "bottom-start" | "left" | "left-end" | "left-start" | "right" | "right-end" | "right-start" | "top" | "top-end" | "top-start"
Default undefined

showOn

Description - click: Popover will show on left click or tap on mobile. - context-menu: Popover will show on right click or press on mobile. - hover: Popover will show on hover or tap on mobile. Clicking the trigger or the content doesn’t dismiss it. It closes when the pointer leaves, or on a click outside.
Attribute show-on
Type "click" | "context-menu" | "hover"
Default "click"

Events

orbDismissEnd

Description Emits when the popover is closed
Type CustomEvent<any>

orbDismissStart

Description Emits before the popover starts dismissing
Type CustomEvent<any>

orbPresentEnd

Description Emits when the popover is opened
Type CustomEvent<any>

orbPresentStart

Description Emits before the popover starts opening
Type CustomEvent<any>

Methods

hide

Signature hide(role?: string, data?: any) => Promise<void>
Parameters role (string)
data (any)

show

Description Opens the popover. Pass a pointer event, or anything with getBoundingClientRect, such as a Range, to open it there. Calling it again while open moves it.
Signature show(at?: Anchor) => Promise<void>
Parameters at (Pick<MouseEvent, "clientX" | "clientY"> | { getBoundingClientRect(): DOMRect; contextElement?: Element; })

Shadow Parts

Part Description
"arrow"
"content"

Dependencies

Used by

Graph

graph TD; orb-cell --> orb-popover orb-datepicker --> orb-popover orb-rich-text --> orb-popover style orb-popover fill:#f9f,stroke:#333,stroke-width:4px