Skip to content
Harness Design System

Tooltip

The Tooltip component provides additional information for an element in a small overlay.

Usage

import { Tooltip } from '@harnessio/ui/components'
// ...
return (
<Tooltip.Provider> {/* typically wrapped around the entire app */}
{/* ... */}
<Tooltip.Root>
<Tooltip.Trigger>Hover me</Tooltip.Trigger>
<Tooltip.Content>
<p>This is a tooltip</p>
</Tooltip.Content>
</Tooltip.Root>
</Tooltip.Provider>
)

Anatomy

<Tooltip.Provider>
<Tooltip.Root>
<Tooltip.Trigger />
<Tooltip.Content>
<Tooltip.Arrow />
</Tooltip.Content>
</Tooltip.Root>
</Tooltip.Provider>

API Reference

Provider

The provider component that manages tooltips. Typically wrapped around the entire app.

<Tooltip.Provider
delayDuration={700} // [OPTIONAL] delay from when the mouse enters until the tooltip opens
skipDelayDuration={300} // [OPTIONAL] how much time a user has to enter another trigger without incurring a delay again
disableHoverableContent // [OPTIONAL] immediately close the tooltip when the mouse leaves the trigger
>
{/* ... */}
</Tooltip.Provider>
PropRequiredDefaultType
delayDurationfalse700number
skipDelayDurationfalse300number
disableHoverableContentfalsefalseboolean

Root

The Root component of a tooltip can be used in both controlled and uncontrolled modes. In uncontrolled mode, you can use the defaultOpen prop to specify the initial open state of the tooltip. In controlled mode, you can manage the open state externally by using the open and onOpenChange props. The open prop allows you to control the open state directly, while the onOpenChange prop is an event handler called whenever the open state changes.

<Tooltip.Root
defaultOpen // [OPTIONAL] initial open state
open // [OPTIONAL] controlled open state
onOpenChange={onChange} // [OPTIONAL] event handler called when the open state changes
delayDuration={700} // [OPTIONAL] override default delay duration
disableHoverableContent // [OPTIONAL] override default setting for disabling hoverable content
>
{/* ... */}
</Tooltip.Root>
PropRequiredDefaultType
defaultOpenfalsefalseboolean
openfalseboolean
onOpenChangefalse(open: boolean) => void
delayDurationfalsenumber
disableHoverableContentfalseboolean

Trigger

The button that toggles the tooltip. This component is based on the native button element and supports all of its props.

<Tooltip.Trigger
asChild // [OPTIONAL] render the trigger as the child
className="class" // [OPTIONAL] additional CSS classes
>
<button>Hover over me</button>
</Tooltip.Trigger>
PropRequiredDefaultType
asChildfalseboolean
classNamefalsestring

Content

The component that pops out when the tooltip is open.

<Tooltip.Content
side="top" // [OPTIONAL] preferred side
sideOffset={5} // [OPTIONAL] distance from the trigger
align="center" // [OPTIONAL] preferred alignment
alignOffset={-4} // [OPTIONAL] offset from the alignment
avoidCollisions // [OPTIONAL] avoid collisions
collisionBoundary={[el]} // [OPTIONAL] boundary to use for collision detection
collisionPadding={4} // [OPTIONAL] padding to apply to the collision detection
sticky="partial" // [OPTIONAL] sticky behavior
className="class" // [OPTIONAL] additional CSS classes
>
{/* Tooltip content */}
</Tooltip.Content>
PropRequiredDefaultType
sidefalse'top''top' | 'right' | 'bottom' | 'left'
sideOffsetfalse5number
alignfalse'center''start' | 'center' | 'end'
alignOffsetfalse-4number
avoidCollisionsfalsetrueboolean
collisionBoundaryfalseElement | null | Array<Element | null>
collisionPaddingfalse4number
stickyfalse'partial''partial' | 'always'
classNamefalsestring