Raft Design System

Components · Overlays

Tooltip

One line that appears on hover, keyboard focus or a press and hold, and gives something without a visible label its name, its consequence or its shortcut.

StableAlso called Hint
import { Tooltip } from "@botiverse/raft-ui";

A tooltip is one line that appears on hover, on keyboard focus or, on a touch screen, on a press and hold, and gives something without a visible label its name, its consequence or its keyboard shortcut. Icon buttons, truncated names, runtime chips and the items of the desktop rail use it.

When to use

SituationUse
An icon button, a truncated name, a runtime chip ("Runs on Martin's MacBook")Tooltip
An item of the desktop railTooltip on the right, with the destination's name (AppRail)
A label that is already visible on the controlNothing: don't repeat it in a tooltip
Content with a link or a buttonPopover
A person or an agentPreviewCard

Anatomy

  • TooltipProvider: sets the open delay for the tooltips inside it. In raft-ui they open without delay.
  • Tooltip: the root. Required.
  • TooltipTrigger: the element the tooltip describes. Required. openOnLongPress and openOnTap set how it opens on a touch screen (Touch screens).
  • TooltipContent: the tooltip, with a small arrow toward the trigger. A leading icon and a Kbd for the shortcut can sit inside it. Required.
  • TooltipPortal: a lower-level part.

The tooltip is layer-hud with foreground-on-hud text, like a toast (Color).

Behavior

  • It opens above its trigger, centered on it, and flips below when there is no room above.
  • In a phone sheet or a drawer, a tooltip on a control in the body stays under the sheet's head; one on a head button opens above it as usual (Dialog).
  • The room above ends where the window's own controls begin. A desktop shell that draws its caption buttons over the top of the page sets the height of that band as --raft-frame-inset-top on the root element, and a tooltip that would open into the band flips below; one beside its trigger moves down out of it. The web sets none.
  • On a trigger in that band it flips away from --raft-frame-inset-start and --raft-frame-inset-end the same way. They are the band's corners (the macOS traffic lights, the Windows caption buttons), not columns: under the band they bound nothing (Page structure).
  • side="right" puts it beside the trigger, as on the rail; side="bottom" puts it under the trigger.
  • It wraps at 20rem, or at the space left in the window.
  • It closes when the pointer leaves, when focus leaves and on Esc.

Touch screens

A touch screen has no hover, so there a tooltip opens on a press and hold, the same as the mobile app's tooltip. Without it, a disabled button's reason (the one step that would make it usable) was out of reach on a phone; with it, the reason reaches every screen the same way, on the web and in the app.

  • Holding the trigger still for 500ms opens the tooltip: the design system's long press, the moment a long-press menu opens and a touch drag arms (Dragging on a touch screen). The hold doesn't press the trigger: lifting the finger runs no action.
  • It opens on a disabled button too, so a disabled button's reason works by touch. The button must still receive the touch: give it focusableWhenDisabled (aria-disabled), as a disabled button with a reason already has (Button). A natively disabled button takes no touches and its tooltip never opens.
  • A finger that moves more than 10px before the 500ms are up is scrolling, and opens nothing; scrolling across a row of triggers never opens their tooltips.
  • After the hold, the tooltip stays while the finger is down and closes 1.5 seconds after it lifts, time to read the line the finger was covering. A tap anywhere else closes it at once.
  • A short tap presses the trigger, as always, and opens nothing.
  • A long press belongs to the layer that owns it; the tooltip takes it only when nothing else wants it. So by default the hold opens nothing:
    • on a link, whose own long press gives the system's menu (copy the link, open it in a new tab), more useful than a tooltip, and whose name is in its accessible name;
    • inside a long-press owner: an element marked data-long-press-owner. raft-ui marks its own: ContextMenuTrigger, a reorderable tab, a sortable composer attachment, a draggable task. An app marks the element that runs its own long press (a message row with a touch menu, a sortable item): the hold there is its menu or its drag, never both at once.
  • Inside an owner, a disabled button whose reason must still show takes the hold back with openOnLongPress: its tooltip opens, and the owner's menu or drag doesn't start. The trigger carries data-tooltip-long-press, and the touch stops at it, so an owner listening through React (ContextMenuTrigger) never arms; an owner with a DOM listener of its own skips a touch that starts inside [data-tooltip-long-press]. openOnLongPress={false} turns the hold off anywhere else.
  • Every trigger is select-none, so holding a name doesn't select its text.
  • A button that exists only to explain (an ⓘ beside a setting) opens on a tap with openOnTap, and the next tap, on it or anywhere else, closes it. Its tap does nothing else, so a hold to find it would only slow it down. Its click no longer closes the tooltip.

Content

  • Write one name or one short sentence, in sentence case: Search, Runs on Martin's MacBook.
  • Use the same word in the tooltip as in the trigger's aria-label.
  • Put the shortcut after the text, one key per cap: a KbdShortcut at sm from key names, which draws ⌘ K on a Mac and Ctrl K elsewhere (Kbd).
  • Where a disabled control's tooltip also says what would make it usable (the one step the reader can take, or who can do it; never Raft's internal reason, Writing), and the first line names the control (its label cut short on the trigger), put that on a second line in foreground-on-hud-muted, 4px below the name: the name, then the step. The step alone is the tooltip's one line, in its own text color.

Accessibility

  • Tooltip wraps the Base UI Tooltip. It provides the tooltip role and opens on hover, on keyboard focus and, on a touch screen, on a press and hold (Touch screens).
  • A tooltip adds to a name; it doesn't replace it. Give every icon-only button its own aria-label.
  • Touch screens have no hover. The tooltip opens on a press and hold there, which people find only when they look for it: keep a tooltip to what helps but isn't needed (a name, a disabled button's step). What everyone must read goes in the interface.
  • A tooltip on a tag inside a row's button is reached by nothing but the pointer. Put its sentence in the tag as visually hidden text, so it joins the row's name, and keep the tooltip as an extra (Accessibility).

Rules

  • Never put a link, a button or anything people must act on in a tooltip: the pointer can't reach it.

API

Tooltip

PropTypeDefault
actionsRefA ref to imperative actions. - `unmount`: Ends the closing phase of the tooltip after an externally controlled closing animation finishes. Call `preventUnmountOnClose()` in `onOpenChange` first, otherwise the tooltip completes closing on its own. Whether it leaves the DOM is decided by `keepMounted` on the portal. - `close`: Closes the tooltip imperatively when called.RefObject<TooltipRootActions | null>
childrenThe content of the tooltip. This can be a regular React node or a render function that receives the `payload` of the active trigger.ReactNode | PayloadChildRenderFunction<unknown>
defaultOpenWhether the tooltip is initially open.booleanfalse
defaultTriggerIdID of the trigger that the tooltip is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open tooltip.string
disabledWhether the tooltip is disabled.booleanfalse
disableHoverablePopupWhether the tooltip contents can be hovered without closing the tooltip.booleanfalse
handleA handle to associate the tooltip with a trigger. If specified, allows external triggers to control the tooltip's open state. Can be created with the Tooltip.createHandle() method.BaseTooltip.Handle<unknown>
onOpenChangeEvent handler called when the tooltip is opened or closed.(open: boolean, eventDetails: BaseTooltip.Root.ChangeEventDetails) => void
onOpenChangeCompleteEvent handler called after any animations complete when the tooltip is opened or closed.(open: boolean) => void
openWhether the tooltip is currently open.boolean
trackCursorAxisDetermines which axis the tooltip should track the cursor on."none" | "both" | "x" | "y"'none'
triggerIdID of the trigger that the tooltip is associated with. This is useful in conjunction with the `open` prop to create a controlled tooltip. There's no need to specify this prop when the tooltip is uncontrolled (that is, when the `open` prop is not set).string

TooltipContent

PropTypeDefault
containerHTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null>
portalPropsTooltipPortalProps
alignHow to align the popup relative to the specified side.Align"center"
alignOffsetAdditional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment.number | OffsetFunction0
anchorAn element to position the popup against. By default, the popup will be positioned against the trigger.Element | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null)
arrowPaddingMinimum distance to maintain between the arrow and the edges of the popup.number5
collisionAvoidanceDetermines how to handle collisions when positioning the popup.CollisionAvoidanceCONTENT_COLLISION_AVOIDANCE
collisionBoundaryAn element or a rectangle that delimits the area that the popup is confined to.Boundary'clipping-ancestors'
collisionPaddingAdditional space to maintain from the edge of the collision boundary.Padding5
disableAnchorTrackingWhether to disable the popup from tracking any layout shift of its positioning anchor.booleanfalse
positionMethodDetermines which CSS `position` property to use."fixed" | "absolute""fixed"
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)
sideWhich side of the anchor element to align the popup against. May automatically change to avoid collisions.Side"top"
sideOffsetDistance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment.number | OffsetFunction0
stickyWhether to maintain the popup in the viewport after the anchor element was scrolled out of view.booleanfalse

Also takes the attributes of its element.

TooltipPortal

PropTypeDefault
containerA parent element to render the portal element into.HTMLElement | ShadowRoot | RefObject<HTMLElement | ShadowRoot | null>
keepMountedWhether to keep the portal mounted in the DOM while the popup is hidden.booleanfalse
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

TooltipProvider

PropTypeDefault
childrenReactNode
closeDelayHow long to wait before closing a tooltip. Specified in milliseconds.number
delayHow long to wait before opening the tooltip on hover. Specified in milliseconds.number0
timeoutAnother tooltip will open instantly if the previous tooltip is closed within this timeout. Specified in milliseconds.number400

TooltipTrigger

PropTypeDefault
openOnLongPressOn a touch screen, holding the trigger for 500ms opens the tooltip, on a disabled trigger too (`focusableWhenDisabled`). By default it does, unless the touch is in a link (its own long-press menu) or inside an element that owns the long press (`data-long-press-owner`: a `ContextMenuTrigger`, a touch-draggable item, an app's long-press row). `false` turns it off; `true` takes the hold even inside an owner, for a disabled button whose reason must show there: the owner doesn't open.boolean
openOnTapOn a touch screen, a tap opens the tooltip and the next tap closes it. Only for a button that exists to explain (an ⓘ), whose tap does nothing else. Its click no longer closes the tooltip (`closeOnClick` is `false` unless set).booleanfalse
closeDelayHow long to wait before closing the tooltip. Specified in milliseconds.number0
closeOnClickWhether the tooltip should close when this trigger is clicked.booleantrue
delayHow long to wait before opening the tooltip on hover. Specified in milliseconds.number600
disabledIf `true`, the tooltip will not open when interacting with this trigger. Note that this doesn't apply the `disabled` attribute to the trigger element. If you want to disable the trigger element itself, you can pass the `disabled` prop to the trigger element via the `render` prop.booleanfalse
handleA handle to associate the trigger with a tooltip.BaseTooltip.Handle<unknown>
payloadA payload to pass to the tooltip when it is opened.{}
renderAllows you to replace the component's HTML element with a different tag, or compose it with another component.ReactElement | ((props, state) => ReactElement)

Also takes the attributes of its element.

Changes

  • 0.104.0 · Design SystemTooltips on a touch screen, and who owns a long press ([Tooltip › Touch screens](https://raft-design.botiverse.build/components/tooltip/#touch-screens), [States › Dragging on a touch screen](https://raft-design.botiverse.build/foundations/states/#dragging-on-a-touch-screen)): on a touch screen a tooltip opens on a press and hold, on a disabled button too (focusableWhenDisabled); a long press belongs to the layer that owns it (a long-press menu, a touch drag, a link), and the tooltip takes it only when nothing else wants it. Changed in this release: TooltipTrigger, and the long-press owners ContextMenuTrigger, SortableTabsTab, SortableComposerAttachment and TaskDraggable.
  • 0.103.4 · FixedFrame insets (Popover, DropdownMenu, ContextMenu, Select, Combobox, ComboboxSelect, Tooltip, PreviewCard, CoachMark, NotificationCenter, MobileNavServerPopover, ToastPositioner, ComposerSuggestionList): --raft-frame-inset-start and --raft-frame-inset-end are the corners of the window's top band (--raft-frame-inset-top), not columns down its sides. A popup anchored under the band keeps its own padding from the window's edge; only one anchored in the band (a title-bar control, or a context menu opened in the bar) keeps 8px clear of a corner.
  • 0.103.3 · FixedFrame insets (useFrameInsets, frameCollisionBoundary): opening a positioned popup (Popover, DropdownMenu, Select, Combobox, ComboboxSelect, ContextMenu, Tooltip, PreviewCard, NotificationCenter, MobileNavServerPopover, ComposerSuggestionList) no longer stalls the main thread when --raft-frame-inset-* holds a calc() or env(titlebar-area-*) expression on an overlay title bar.
  • 0.102.20 · FixedMessageItemToolbarButton: shows its aria-label as a tooltip on hover and keyboard focus, with an optional shortcut after it; tooltip replaces the text and tooltip={false} leaves it out. Inside a caller's own TooltipTrigger it adds none, and an open tooltip doesn't keep the toolbar shown.
  • 0.10.0 · ChangedTooltip, ComboboxSelect options, Steps and Timeline use the type scale instead of fixed sizes, so they follow the desktop values.