Components

Tooltip

A short label that shows when a control is hovered or focused. Use it to name an icon button and show its shortcut.

Usage

import { Tooltip } from 'nyctoui/tooltip'

<Tooltip content="Copy link">
  <Button iconOnly aria-label="Copy link">
    <IconLink size={16} />
  </Button>
</Tooltip>

Give Tooltip its text as content and wrap the control. The child becomes the trigger, so it must take a ref and spread props, as every NyctoUI control does.

A tooltip is a visual label only. It never opens on touch, and screen readers don’t rely on it, so an icon-only trigger needs an aria-label that matches the text. Don’t put anything in a tooltip that people need to read; for that, use a Popover.

Good for

  • Naming icon buttons in an editor toolbar, with their shortcuts.
  • The full name of a truncated row in a sidebar.
  • Exact time on a relative date such as “2h ago” in a feed.
  • The name of a collaborator’s avatar in a document header.

Anatomy

<TooltipProvider>
  <Tooltip>
    <TooltipTrigger />
    <TooltipContent>
      <TooltipShortcut />
    </TooltipContent>
  </Tooltip>
</TooltipProvider>

The parts are for when the shorthand isn’t enough: a custom delay on the trigger, offsets, or content beyond a label and a shortcut.

Examples

Shortcut

Pass keys as shortcut and they sit after the label, a step quieter.

Sides

Tooltips open above the trigger. Use side where that would cover something, such as along the top edge of a page.

Group

Once one tooltip has opened, its neighbors open at once. A TooltipProvider sets the delay for the tooltips inside it; wrap a toolbar in one, or the whole app.

Composed

The same tooltip built from parts, here opening with no delay and below the trigger.

Best practices

Do
  • Keep it to a few words of plain text, the name of the control or a short fact.
  • Add a tooltip to every icon-only button, with the same words as its aria-label.
  • Show the shortcut with the shortcut prop, so people can learn it.
Don’t
  • Put links or buttons in a tooltip. Use a popover.
  • Put anything people need to read to finish a task in a tooltip. It never opens on touch.
  • Use a tooltip to explain why a control is disabled. Write the reason next to it.

API reference

Tooltip

Holds the open state. With content, also renders the trigger and the bubble. Renders no element of its own.

PropTypeDefault
content
Shorthand for the tooltip’s text. When set, children is the trigger element.
ReactNode—
shortcut
Shorthand: keys shown after content.
ReactNode—
side
Shorthand: which side of the trigger to open on. flips when it would clip.
'top' | 'right' | 'bottom' | 'left''top'
align
Shorthand: how to line up with the trigger along that side.
'start' | 'center' | 'end''center'
defaultOpen
Starts open. For uncontrolled use.
booleanfalse
open
Whether the tooltip is open. For controlled use.
boolean—
onOpenChange
Called when the tooltip opens or closes.
(open: boolean, details) => void—
disabled
Stops the tooltip from opening.
booleanfalse
delay
Milliseconds of hover before opening. Defaults to the provider’s.
number500
closeOnPress
Closes the tooltip when the trigger is pressed.
booleantrue

TooltipProvider

Sets the hover delay for the tooltips inside it. Renders no element.

PropTypeDefault
delay
Milliseconds of hover before a tooltip opens.
number500

TooltipTrigger

The element the tooltip labels. Renders a <button>.

PropTypeDefault
render
Replaces the rendered element, e.g. render={<Button />}.
ReactElement | function—

TooltipContent

The bubble. Renders a <div> in the top layer.

PropTypeDefault
side
Which side of the trigger to open on. Flips when it would clip.
'top' | 'right' | 'bottom' | 'left''top'
align
How to line up with the trigger along that side.
'start' | 'center' | 'end''center'
sideOffset
Gap between the trigger and the bubble, in pixels.
number6
alignOffset
Shift along the alignment axis, in pixels.
number0
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

TooltipShortcut

Keys after the label, aligned to the end. Renders a <span>.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—