Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popover and tooltip API improvements #4595

Open
gfellerph opened this issue Feb 4, 2025 · 0 comments
Open

Popover and tooltip API improvements #4595

gfellerph opened this issue Feb 4, 2025 · 0 comments
Labels
📦 components Related to the @swisspost/design-system-components package
Milestone

Comments

@gfellerph
Copy link
Member

Discussed in #4513

Originally posted by gfellerph January 23, 2025
Tooltips and popovers are a much discussed topic.

This 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

Tooltip proposal

Design: https://www.figma.com/design/JIT5AdGYqv6bDRpfBPV8XR/Foundations-%26-Components-Next-Level?node-id=21-180&m=dev

Behaviour

  • Opens on interest (hover, focus, long-press)
  • Closes on interest-lost on either the trigger or the tooltip itself (unless no-hover is set), enabling users to interact with the tooltip, for example highlighting text for copy/paste or translation
  • Implements light-dismiss, closing on escape keypress or outside click and also closes when another tooltip is opened (default functionality of the popover 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 to undefined
  • 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 there
  • id, 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 trigger

Tooltip 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".

image

Setup

<!-- Tooltip is connected via for/id attributes -->
<post-tooltip-trigger for="bold-description">
  <button>B</button>
</post-tooltip-trigger>
<post-tooltip id="bold-description">Bold</post-tooltip>

<!-- Tooltip is nested inside the trigger, no for/id attributes necessary -->
<post-tooltip-trigger>
  <button>B</button>
  <post-tooltip>Bold</post-tooltip>
</post-tooltip-trigger>

Popover proposal

Design: https://www.figma.com/design/JIT5AdGYqv6bDRpfBPV8XR/Foundations-%26-Components-Next-Level?node-id=21-173&m=dev

Behaviour

  • Opens according to it's trigger-on prop or on click by default
  • Closes based on trigger action or on light dismiss
  • Does not open in modal mode (not supported by the popover 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 default
  • 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 to undefined (intended to be used together with trigger-on="interest"

Popover trigger props

  • for, string connects the trigger to it's popover, optional if the tooltip is nested inside the trigger
  • trigger-on, click|interest|manual specifies what action triggers the popover.
    • click, the default option open/closes the popover on click
    • interest, the popover opens on hover, long-press and focus
    • manual, 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 popover
  • trigger-action, toggle|show|hide specifies if the trigger toggles a popover on repeated actions, only opens or only closes it

Background 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.

image

Setup

<!-- Popover is connected via for/id attributes -->
<post-popover-trigger for="more-info">
  <button>show info</button>
</post-popover-trigger>
<post-popover id="more-info">
  <h3>Additional info</h3>
  <p>Lorem...</p>
  <a href="/goto">Read more about it</a>
</post-popover>

<!-- Popover is nested inside the trigger, no for/id attributes necessary -->
<post-popover-trigger>
  <button>show info</button>
  <post-popover>
    <h3>Additional info</h3>
    <p>Lorem...</p>
    <a href="/goto">Read more about it</a>
  </post-popover>
</post-tooltip-trigger>

Footnotes

  1. https://component.gallery/components/tooltip/

  2. https://component.gallery/components/popover/

@gfellerph gfellerph added the 📦 components Related to the @swisspost/design-system-components package label Feb 4, 2025
@gfellerph gfellerph modified the milestones: Breaking changes, Design v2 Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 components Related to the @swisspost/design-system-components package
Projects
Status: 👀 Triage
Development

No branches or pull requests

1 participant