Tooltip

A short label that appears when you point at or focus an element, to say what it is or does.

import { Tooltip } from '@halo-ds/react';

When to use it

Use a tooltip to name things that have no visible label, like Compact buttons and icon-only Buttons, or to show the full text of something that is cut off. It appears on hover or keyboard focus and disappears when you move away.

Tooltips hold short text only. If you need anything people can click, use a Popover instead.

Do

  • Use tooltips to name icon-only buttons.
  • Keep them to a few words, in sentence case, with no full stop.
  • Match the tooltip to the button's accessible name.
  • Add a keyboard shortcut when there is one, for example "Bold (Ctrl B)".

Don't

  • Put links, buttons or anything clickable inside a tooltip.
  • Hide information people need to finish a task.
  • Repeat a label that is already visible.
  • Add tooltips to disabled buttons; they can't be focused, so keyboard users never see them.

Tooltip or Popover?

Both float next to an element. Choose by what goes inside.

  • Tooltip: A few words of plain text. Appears on hover or focus; nothing inside to click. Names an icon, explains a control or shows truncated text.
  • Popover: Richer content: text, links, buttons, forms. Opens on click and stays open until closed. Menus, pickers, more details, quick settings.

Props

Tooltip props

PropTypeWhat it does
content (required)ReactNodeThe tooltip text. Keep it to a few words. Figma: Label.
side`TooltipSide \undefined`Which side it appears on. Flips if there is no room. Figma: Placement.
delay`number \undefined`Milliseconds to wait on hover before showing. Keyboard focus shows it straight away.
children (required)`ReactElement<unknown, string \JSXElementConstructor<any>>`The element the tooltip describes. It must accept a ref and focus/hover events.
classNames`Partial<Record<TooltipPart, string>> \undefined`Extra class names for the parts inside the component, by part name, like { header: 'my-header' }.
styles`Partial<Record<TooltipPart, CSSProperties>> \undefined`Inline styles for the parts inside the component, by part name, like { footer: { gap: 4 } }.

It also takes the usual HTML attributes for its element.

Examples

Overview

import { Button, Tooltip } from '@halo-ds/react';

export default function Example() {
  return (
    <Tooltip content="Copies the link to your clipboard">
      <Button variant="secondary">Copy link</Button>
    </Tooltip>
  );
}

Placement

Four sides. If there is no room, the tooltip flips to the opposite side.

import { CompactButton, Tooltip } from '@halo-ds/react';
import { Copy, DownloadSimple, Gear, Trash } from '@phosphor-icons/react';

export default function Demo() {
  return (
    <div className="demo-row" style={{ gap: 24 }}>
      <Tooltip content="Delete" side="top"><CompactButton variant="ghost" aria-label="Delete"><Trash /></CompactButton></Tooltip>
      <Tooltip content="Copy" side="bottom"><CompactButton variant="ghost" aria-label="Copy"><Copy /></CompactButton></Tooltip>
      <Tooltip content="Settings" side="left"><CompactButton variant="ghost" aria-label="Settings"><Gear /></CompactButton></Tooltip>
      <Tooltip content="Download" side="right"><CompactButton variant="ghost" aria-label="Download"><DownloadSimple /></CompactButton></Tooltip>
    </div>
  );
}

More: https://halodesignsystem.dev/components/tooltip