Skip to main content

Popover

A configurable Popover component used to show content on the screen when a user clicks or hovers on a control button or in defined area. By default aria-describedby is used for Accessiblity. However, it is possible to use aria-labelledby instead with the prop useLabelledby. This is useful for Emojis or Icons as triggers.

Viewport-aware positioning

The component automatically keeps the tooltip fully visible regardless of screen size or trigger position:

  • Flip — when the preferred placement has insufficient space, the tooltip switches to the opposite side (topbottom, leftright).
  • Shift — when neither opposite side has enough room (e.g. a narrow mobile viewport), the tooltip is shifted along the axis with a translateX / translateY offset so it never overflows the document.
  • Cross-axis fallback — for left / right placements on very narrow screens where no horizontal space is available on either side, the tooltip falls back to top placement above the trigger.

No configuration is required — the logic runs automatically on every open.

Import

// with @dhl-official/react-library:
import { DhlPopover } from "@dhl-official/react-library"
// with @dhl-official/ui-libraries/react-library:
import { DhlPopover } from "@dhl-official/ui-libraries/react-library"

Code

<DhlPopover>
<DhlButton slot="triggerEl" size="sm">
<span aria-hidden="true"></span>
</DhlButton>
<p>View and manage settings</p>
</DhlPopover>

Interactive Demo

Migrating from DUIL 1.0

  • Discontinue use of Popper.js.
  • Update placement to hold values top, right, bottom and left
  • Add useLabelledby
  • Remove offset
  • Remove popperOptions
  • Remove popoverTriggerAriaLabel
  • Remove showCloseButton
  • Remove closeButtonAriaLabel
  • Remove heading
  • Remove trigger
  • Remove closeOnOutsideClick

Readme

Properties

PropertyAttributeDescriptionTypeDefault
dataClassNamedata-class-nameAn optional prop for the class of the root element.stringundefined
dataIddata-idAn optional prop. Gives a valid HTML ID attribute value for the component.string`dhl-popover-${getRandomString()}`
dataTestiddata-testidAn optional prop. The test id attached to the component as a data-testid attribute.stringundefined
placementplacementAn optional prop, it controls where the tooltip is placed relative to the trigger element, defaults to 'none'. Internal business logic determines if the explicit position set with this prop allows the component to be entirely shown in the visible viewport area, if not, it tries to re-position it so that it will. Use 'none' to display without an arrow."bottom" | "left" | "none" | "right" | "top"DHL_POPOVER.PLACEMENT.NONE
showCloseButtonshow-close-buttonAn optional prop, set to true to render a close button (×) inside the tooltip. Useful as a dismiss affordance on mobile/touch devices.booleanfalse
useLabelledbyuse-labelledbyAn optional prop, set to true it adds the aria-labelledby attribute to the trigger element. If this prop is set to false, the attribute aria-describedby` is used instead.booleanundefined
visiblevisibleAn optional prop, set to true it set the component to its visible state.booleanfalse

Dependencies

Used by

Depends on

Graph


Built by DHL User Interface Library Team!