Skip to Content

Tooltip

A tooltip displays a brief description of an element on hover or focus.

Usage

import { Button, Tooltip, TooltipTrigger } from "@opengovsg/oui"
<TooltipTrigger>
  <Button>Hover me</Button>
  <Tooltip>This is a tooltip</Tooltip>
</TooltipTrigger>

OUI exports 2 tooltip-related components:

  • TooltipTrigger: Wraps a trigger element and a Tooltip. Handles showing and hiding the tooltip on hover, focus, and keyboard interactions.
  • Tooltip: The tooltip overlay that displays the content.

Note: Tooltips are not shown on touch screen interactions. Ensure that your UI is usable without tooltips, or use an alternative component such as a Popover to show information in an adjacent element.

Examples

Placement

Use the placement prop on Tooltip to control the position of the tooltip relative to its trigger. Supported values include top, bottom, start, end, and their combinations (e.g., top start, bottom end).

Defaults to top.

Without Arrow

Set showArrow={false} to hide the arrow indicator on the tooltip.

Offset

Use the offset prop to control the distance between the tooltip and the trigger element. The default offset is 10.

Controlled

You can control the tooltip's open state using the isOpen and onOpenChange props on TooltipTrigger.

Tooltip is closed

Slots

  • base: The main container of the tooltip.
  • arrow: The arrow indicator pointing to the trigger element.

Custom Styles

You can customize the Tooltip component by passing custom Tailwind CSS classes to the component slots via the classNames prop.

Accessibility

  • Tooltip is shown on hover and keyboard focus of the trigger element.
  • Tooltips have a warmup delay (300ms) before appearing. Once a tooltip is shown, subsequent tooltips in the same group appear instantly.
  • Content outside the tooltip is not blocked — tooltips are non-modal.
  • The trigger element must have a proper ARIA role or use a semantic HTML element (e.g., <button>) so that screen readers can announce the tooltip.
  • Press the Esc key to dismiss the tooltip.

Props

Tooltip

PropTypeDefaultDescription
childrenReact.ReactNode-The content of the tooltip
placementPlacement"top"The placement of the tooltip relative to the trigger
offsetnumber10The additional offset along the main axis from the trigger
crossOffsetnumber0The additional offset along the cross axis
shouldFlipbooleantrueWhether the tooltip flips when insufficient space is available
containerPaddingnumber12The spacing between the tooltip and the edge of the surrounding container
showArrowbooleantrueWhether to show the arrow pointing to the trigger element
variant"default" | "unstyled""default"The visual variant of the tooltip
radius"none" | "sm" | "default" | "md" | "lg" | "full""sm"The border radius of the tooltip
classNamesSlotsToClasses<TooltipSlots>-Custom CSS classes for component slots

TooltipTrigger

PropTypeDefaultDescription
childrenReact.ReactNode-The trigger element and tooltip
delaynumber300The delay (in ms) before the tooltip opens on hover
closeDelaynumber0The delay (in ms) before the tooltip closes
isOpenboolean-Whether the tooltip is open (controlled)
defaultOpenboolean-Whether the tooltip is open by default (uncontrolled)
isDisabledboolean-Whether the tooltip trigger is disabled
onOpenChange(isOpen: boolean) => void-Callback when the tooltip open state changes