Tooltip

A popup displaying information when an element receives keyboard focus or mouse hover.

Installation

If @melio-ui/react is already installed globally, you can skip this step.

Import

  • TooltipRoot: All parts of the tooltip are included.
  • TooltipTrigger: Used to activate or open the Tooltip component.
  • TooltipPortal: Portal the overlay and content portion into the body.
  • TooltipContent: Includes the content that will be displayed in the open tooltip.
  • TooltipArrow: An optional arrow element for the tooltip, to be rendered within TooltipContent for visual association.

Another way to import

'use client';
import { Tooltip } from '@melio-ui/tooltip';
<Tooltip.Root>
<Tooltip.Trigger asChild>
<button>Tooltip</button>
</Tooltip.Trigger>
<Tooltip.Portal>
<Tooltip.Content>
tooltip message
<Tooltip.Arrow />
</Tooltip.Content>
</Tooltip.Portal>
</Tooltip.Root>;

'use client' must be used when rendering on the server side.

API Reference

TooltipRoot

All parts of the tooltip are included.

PropTypeDefaultDescription
openboolean-Sets whether the tooltip content is open or closed.
defaultOpenboolean-When first rendered, the tooltip content is in an opened state. Use when there is no need to control the opened state.
onOpenChange(open: boolean) => void-This is an event handler that is triggered when the open state of the tooltip content changes.

TooltipTrigger

Used to activate or open the Tooltip component.

PropTypeDefaultDescription
asChildboolean-Changes the default rendering element passed as a child, merging its props and behavior.
Data attributeValues
[data-state]"open" | "closed"

TooltipPortal

Portal the overlay and content portion into the body.

PropTypeDefaultDescription
containerHTMLElement | (() => HTMLElement)document.bodySpecifies the container element to which the content should be portaled.

TooltipContent

Includes the content that will be displayed in the open tooltip.

PropTypeDefaultDescription
side"top" | "right" | "bottom" | "left""top"The ideal side of the trigger to render on when it's open.
sideOffsetnumber0The pixel distance from the trigger.
align"start" | "center" | "end""center"The desired alignment with the trigger, which may adjust if collisions happen.
alignOffsetnumber0A pixel offset from the "start" or "end" alignment choices.
Data attributeValues
[data-state]"open" | "closed"
[data-side]"top" | "right" | "bottom" | "left"
[data-align]"start" | "center" | "end"

TooltipArrow

An optional arrow element for the tooltip, to be rendered within TooltipContent for visual association.

PropTypeDefaultDescription
asChildboolean-Changes the default rendering element passed as a child, merging its props and behavior.
widthnumber10The arrow's width measured in pixels.
heightnumber5The arrow's height measured in pixels.

Examples

Display arrow

<TooltipRoot>
<TooltipTrigger asChild>
<button type="button" style={{ width: 200, border: '1px solid #5f76bb', padding: 5 }}>
Hover me
</button>
</TooltipTrigger>
<TooltipPortal>
<TooltipContent>
tooltip message
<TooltipArrow />
</TooltipContent>
</TooltipPortal>
</TooltipRoot>

Position Settings

<TooltipRoot>
<TooltipTrigger asChild>
<button type="button" style={{ width: 200, border: '1px solid #5f76bb', padding: 5 }}>
Hover me
</button>
</TooltipTrigger>
<TooltipPortal>
<TooltipContent side="bottom" align="end">
tooltip message
<TooltipArrow />
</TooltipContent>
</TooltipPortal>
</TooltipRoot>
Prev
DocsMelioUI
Copyright © Ahn Co. All rights reserved.