Skip to main content

Tooltip

Source ↗

A Tooltip is a small, non-interactive overlay that displays brief informational text when hovering over or focusing on an element. It is built on top of the Popover component.

Key Characteristics

  • Hover-Triggered: Automatically shows on hover with configurable delay.
  • Non-Interactive: Unlike Popover, tooltips are meant for displaying simple text hints, not interactive content. Still it's possible to interact with the tooltip content if/when needed via hoverableContent prop.
  • Accessible: Works with keyboard focus and follows accessibility best practices.

Import

import { Tooltip } from '@andrejground/lab';

Customization

Add your styles and your component is ready to be used.

import { Tooltip, TooltipProps } from '@andrejground/lab';
import styles from './MyTooltip.module.scss';

type Props = TooltipProps;

function MyTooltip(props: Props) {
return (
<Tooltip
{...props}
classNames={{
...props.classNames,
content: styles.tooltipContent,
}}
/>
);
}

export default MyTooltip;

Usage

Placement

Delay Show

Control the delay before showing the tooltip with delayShow prop.

Delay Hide

Control the delay before hiding the tooltip with delayHide prop.

Hoverable Content

Use hoverableContent prop to keep the tooltip visible when hovering over the tooltip content.

Controlled

Open: false

API

Tooltip Props

PropTypeDefaultDescription
childrenReactNode-The element that triggers the tooltip
contentReactNoderequiredContent displayed inside the tooltip
placementPopoverPlacement"top-center"Preferred placement of the tooltip relative to the trigger
offsetnumber8Distance in pixels between the tooltip and the trigger
sizePopoverSize"small"Controls the width of the tooltip
isOpenboolean-Controls the tooltip open state (controlled mode)
isDisabledboolean-Disables the tooltip
showArrowbooleantrueShows an arrow pointing toward the trigger
shouldFlipbooleantrueFlips placement when there is not enough space
shouldCloseOnClickOutsidebooleantrueCloses the tooltip when clicking outside of it
shouldCloseOnEscbooleantrueCloses the tooltip when the Escape key is pressed
shouldCloseOnTriggerBlurbooleantrueCloses the tooltip when the trigger loses focus
openOnFocusbooleantrueOpens the tooltip when the trigger receives focus
delayShownumber0Delay in milliseconds before showing the tooltip
delayHidenumberhoverableContent ? 200 : 0Delay in milliseconds before hiding the tooltip
hoverableContentbooleanfalseKeeps the tooltip open while hovering over its content
triggerWrapperboolean-Wraps the trigger in a span instead of using Slot
fullWidthTriggerWrapperboolean-Makes the trigger wrapper take full width
onOpen() => void-Callback fired when the tooltip opens
onClose() => void-Callback fired when the tooltip closes
onClickOutside() => void-Callback fired when clicking outside the tooltip
onOpenChange(isOpen: boolean) => void-Callback fired when the open state changes
onTriggerFocus() => void-Callback fired when the trigger receives focus
onTriggerBlur() => void-Callback fired when the trigger loses focus
classNamesTooltipClassNames-Custom class names for the tooltip slots