Popover and tooltip API improvements #4595
Labels
📦 components
Related to the @swisspost/design-system-components package
needs: 🏓 dev roundtable
To be discussed at the roundtable of esteemed developers
Milestone
Discussed in #4513
Originally posted by gfellerph January 23, 2025
Tooltips and popovers are a much discussed topic.
post-popovercontainer
promotes to Top Layer, causing UI overlap issues #4398<post-popovercontainer>
#4169This is a proposal to define a more flexible API and clean up some issues that have arisen after the first implementations have been used in the real world.
Distinction
Tooltip
A means of displaying a description or extra information about an element, usually on hover, but can also be on click or tap.1
Semantically, tooltips are linked to the trigger element through
aria-describedby
so the tooltip text is automatically being read by screenreaders when focus is on the trigger.Popover
An element that pops up from another element over other content; it differs from a tooltip in that it is usually triggered via click instead of hover and can contain interactive elements.2
Semantically, popovers act as disclosure content which is not linked to the trigger. The trigger has an
aria-expanded
attribute to communicate the current state of the popover.Issues with the current implementations
id
attributes for all the things. An alternative attribute has been proposed to get around the side effects ofid
, but was dismissed as the uniqueness is wanted here ([components]: Tooltip refactoring #4170)Tooltip proposal
Design: https://www.figma.com/design/JIT5AdGYqv6bDRpfBPV8XR/Foundations-%26-Components-Next-Level?node-id=21-180&m=dev
Behaviour
no-hover
is set), enabling users to interact with the tooltip, for example highlighting text for copy/paste or translationpopover
attribute)Tooltip props
arrow
, boolean prop that will display an arrow, false by default (because that's what boolean props should be)delay
,[open-delay]|[open-delay close-delay]
if it's a number, open delay in milliseconds, if it's a string of two numbers, e.g.delay="200 400"
, the first number is the open delay and the second the close delay, defaults toundefined
placement
,string
, one of the floating ui placement possibilities, defaults to 'top'no-hover
,boolean
that defaults to false. Can be used to hide the tooltip when the cursor leaves the trigger, making the tooltip not hoverable. This is not accessible, but a requested feature that would be worked around if not thereid
,string
used to connect<post-tooltip-trigger>
with the target<post-tooltip>
, optional if the tooltip is nested inside the trigger (only triggers the first found tooltip)Background colour can be set by palette utilities.
Tooltip trigger props
for
,string
connects the trigger to it's tooltip, optional if the tooltip is nested inside the triggerTooltip content
A tooltip should contain a descriptive text for the action of it's trigger element, e.g. a button used for toggling bold text should have a tooltip containing the text "Bold". The text should be short and descriptive as it's being read by screenreaders by default. A tooltip can serve as a replacement of the accessible name of an icon button.
Interactive elements are not allowed in tooltips, use a popover with trigger-action="interest".
Setup
Popover proposal
Design: https://www.figma.com/design/JIT5AdGYqv6bDRpfBPV8XR/Foundations-%26-Components-Next-Level?node-id=21-173&m=dev
Behaviour
trigger-on
prop or on click by defaultpopover
attribute anyways)Popover props
id
,string
used to connect<post-popover-trigger>
with the target<post-popover>
, optional if the popover is nested inside the trigger (only triggers the first found popover)placement
,string
, one of the floating ui placement possibilities, defaults to 'top'arrow
,boolean
, show an arrow, false by defaultdelay
,[open-delay]|[open-delay close-delay]
if it's a number, open delay in milliseconds, if it's a string of two numbers, e.g.delay="200 400"
, the first number is the open delay and the second the close delay, defaults toundefined
(intended to be used together withtrigger-on="interest"
Popover trigger props
for
,string
connects the trigger to it's popover, optional if the tooltip is nested inside the triggertrigger-on
,click|interest|manual
specifies what action triggers the popover.click
, the default option open/closes the popover on clickinterest
, the popover opens on hover, long-press and focusmanual
, the popover does not open or close but the trigger wires up all accessibility behaviour. It's expected that the user adds own logic for toggling the popovertrigger-action
,toggle|show|hide
specifies if the trigger toggles a popover on repeated actions, only opens or only closes itBackground colour can be set by palette utilities.
Popover content
Popovers support a broader array of content elements and can provide additional context and contain interactive elements.
Setup
Footnotes
https://component.gallery/components/tooltip/ ↩
https://component.gallery/components/popover/
The text was updated successfully, but these errors were encountered: