Components

Tooltip

Tooltips display a short label or description when the user hovers or focuses on an element.

Stable
GitHub

Anatomy

Anatomy
import {Tooltip} from '@staffbase/spark';

<Tooltip.Root>
  <Tooltip.Trigger />
  <Tooltip.Content />
</Tooltip.Root>

Examples

Icon-only button label

  • There are a few cases in which the tooltip must not provide either accessible name nor description. In this example, the full text can already be accessed by assistive technology and we only need to provide a visual alternative.
  • When there is a large list of items on a page that make use of tooltips to display possibly non-essential information, the delay prop on the Trigger should be used to avoid the tooltip appearing immediately as the user scrolls through. This mimics the native title attribute.

Truncated text

Not recommended:

It is not recommended to use tooltips on non-focusable elements. It can be done in a few exceptional cases after careful consultation and consideration of accessibility.

#BestEmployeeCommunicationApp

Contextual information

  • Contextual tooltips should only be used on focusable elements that have a visible label.
  • In this example, the image and additional name are only helpful for sighted users, but should not be read by a screen reader. Therefore, the decorative image has the attribute alt="" and the text aria-hidden.
  • If the contextual information is more extensive, it is expected there are alternative ways to access it. In this example, the tooltip displays a preview of a user profile and clicking the link would refer you to the full profile.

API reference

Root

Inherits props fromBase UI Tooltip Root

Trigger

Inherits props fromBase UI Tooltip Trigger
NameTypeDescription
children
ReactNode
The element that reveals the tooltip on hover or focus. Passed as a single element, not via a render prop.

Content

Inherits props fromBase UI Tooltip Positioner
NameTypeDescription
is
labeldescriptionvisual-only
How the tooltip relates to its trigger for assistive technology. Use "label" when the tooltip names the trigger (e.g. an icon button), "description" when it adds supplementary detail, or "visual-only" when the content is already conveyed elsewhere.
variant
defaultinverse
The visual style of the tooltip surface.
Default:default
side
topbottomleftrightinline-startinline-end
Which side of the trigger to position the tooltip against.
Default:top
container
HTMLElementRefObject<HTMLElement>
The element the tooltip portal renders into. Use this instead of z-index to control stacking. Defaults to the document body.
children
ReactNode
The content shown inside the tooltip.