A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.
import React from 'react';import * as Tooltip from '@radix-ui/react-tooltip';import { PlusIcon } from '@radix-ui/react-icons';import './styles.css';const TooltipDemo = () => {return (<Tooltip.Provider><Tooltip.Root><Tooltip.Trigger asChild><button className="IconButton"><PlusIcon /></button></Tooltip.Trigger><Tooltip.Portal><Tooltip.Content className="TooltipContent" sideOffset={5}>Add to library<Tooltip.Arrow className="TooltipArrow" /></Tooltip.Content></Tooltip.Portal></Tooltip.Root></Tooltip.Provider>);};export default TooltipDemo;
Provider to control display delay globally.
Opens when the trigger is focused or hovered.
Closes when the trigger is activated or when pressing escape.
Supports custom timings.
Install the component from your command line.
Import all parts and piece them together.
Wraps your app to provide global functionality to your tooltips.
Contains all the parts of a tooltip.
The button that toggles the tooltip. By default, the Tooltip.Content
will position itself against the trigger.
When used, portals the content part into the body
.
The component that pops out when the tooltip is open.
An optional arrow element to render alongside the tooltip. This can be used to help visually link the trigger with the Tooltip.Content
. Must be rendered inside Tooltip.Content
.
Use the Provider
to control delayDuration
and skipDelayDuration
globally.
Use the delayDuration
prop to control the time it takes for the tooltip to open.
You may want to constrain the width of the content so that it matches the trigger width. You may also want to constrain its height to not exceed the viewport.
We expose several CSS custom properties such as --radix-tooltip-trigger-width
and --radix-tooltip-content-available-height
to support this. Use them to constrain the content dimensions.
We expose a CSS custom property --radix-tooltip-content-transform-origin
. Use it to animate the content from its computed origin based on side
, sideOffset
, align
, alignOffset
and any collisions.
We expose data-side
and data-align
attributes. Their values will change at runtime to reflect collisions. Use them to create collision and direction-aware animations.
Create your own API by abstracting the primitive parts into your own component.
This example abstracts all of the Tooltip
parts and introduces a new content
prop.
Use the asChild
prop to convert the trigger part into a slottable area. It will replace the trigger with the child that gets passed to it.