Skip to content

Tooltip

A small label that appears when the pointer rests on something or the keyboard reaches it. It gives the name of a thing or the full text of something cut short.

import { Tooltip } from '@sypnia/ui/react'

On this page
  1. On a button
  2. The full value
  3. Icon buttons have their own
  4. When to use it
  5. For everyone
  6. Props

On a button

Rest the pointer on a button or reach it with Tab.

Code
import { Button, Tooltip } from '@sypnia/ui/react';

// Rest the pointer on the button, or reach it with Tab.
export default function OnAButton() {
  return (
    <div className="sy-row">
      <Tooltip text="Makes a copy of the table with its rows, in this project.">
        <Button icon="copy">Duplicate table</Button>
      </Tooltip>
      <Tooltip text="Last backup: today at 02:00">
        <Button variant="quiet" icon="clock">Backups</Button>
      </Tooltip>
    </div>
  );
}

The full value

A project ID cut to twelve characters; the tooltip has all of it.

Code
import { Button, Tooltip } from '@sypnia/ui/react';

// The full value of something the layout had to cut.
export default function CutText() {
  const id = 'prj_8f2k1x9c4m7q2w5e8r1t6y3u';
  return (
    <Tooltip text={id}>
      <Button variant="quiet" icon="copy" onClick={() => navigator.clipboard?.writeText(id)}>
        <span className="sy-machine">{id.slice(0, 12)}…</span>
      </Button>
    </Tooltip>
  );
}

Icon buttons have their own

IconButton shows its label as a tooltip, so it needs no wrapper.

Code
import { IconButton } from '@sypnia/ui/react';

// An IconButton already carries its tooltip: its label.
export default function IconButtons() {
  return (
    <div className="sy-row">
      <IconButton icon="filter" label="Filter rows" />
      <IconButton icon="sort" label="Sort rows" />
      <IconButton icon="download" label="Export as CSV" />
    </div>
  );
}

When to use it

Use it when

  • A button benefits from one more line: what it will do, or a fact such as the last time it ran.
  • A value was cut to fit and the person may want to read all of it.
  • For icon buttons use IconButton: it already shows its label as a tooltip.

Do not use it when

  • The information is needed to finish the task: write it on the page, as a hint under the field.
  • It would hold a link, a button or more than a short sentence: that is a Popover.
  • The thing it wraps cannot take focus (plain text, a badge): keyboard and touch users would never see it.
  • It explains why a button is disabled: disabled buttons take no focus, so nobody using a keyboard would read it.

For everyone

  • It appears on hover after a short wait and at once on keyboard focus. Escape hides it.
  • The text is tied to the element with aria-describedby, so screen readers say it after the name.
  • On touch screens there is no hover: never put there anything a person on a phone would miss.
  • It is drawn in the top layer, so no panel or table can cut it.

Props

TooltipTypeDefault
textrequired ReactNode
  1. On a button
  2. The full value
  3. Icon buttons have their own
  4. When to use it
  5. For everyone
  6. Props

    Search pages, sections and terms