This option determines whether or not a tooltip should be able to switch sides when constrained by space.
flip.tsx
"use client";import React from "react";import { Button } from "@/lib/components/core/default/button";import { Switch } from "@/lib/components/core/default/switch";import { Tooltip } from "@/lib/components/core/default/tooltip";import { PlusIcon } from "@/lib/icons";function Demo() { const [shouldFlip, setShouldFlip] = React.useState(false); return ( <div className="flex flex-col items-center gap-10"> <Tooltip shouldFlip={shouldFlip} content="Add to library"> <Button shape="square"> <PlusIcon /> </Button> </Tooltip> <Switch isSelected={shouldFlip} onChange={(isSelected) => setShouldFlip(isSelected)}> Should flip </Switch> </div> );}
Offset
The offset is the distance between the end of the tip and the target.
offset.tsx
"use client";import React from "react";import { Button } from "@/lib/components/core/default/button";import { NumberField } from "@/lib/components/core/default/number-field";import { Tooltip } from "@/lib/components/core/default/tooltip";import { PlusIcon } from "@/lib/icons";function Demo() { const [offset, setOffset] = React.useState(10); return ( <div className="flex flex-col items-center gap-10"> <Tooltip offset={offset} content="Add to library"> <Button shape="square"> <PlusIcon /> </Button> </Tooltip> <NumberField label="Offset" value={offset} onChange={(value) => setOffset(value)} className="max-w-[150px]" /> </div> );}
Container padding
To make sure that the tooltip will stay within certain boundaries (e.g., a browser window) it’s possible to define a container and a container padding value to respect. The default value for this is 12 px.
The content of a tooltip can accept custom content, not just text.
custom-content.tsx
import { Button } from "@/lib/components/core/default/button";import { Tooltip } from "@/lib/components/core/default/tooltip";import { PlusIcon } from "@/lib/icons";function Demo() { return ( <Tooltip content={ <p> Add to <b className="font-bold">library</b> </p> } > <Button shape="square"> <PlusIcon /> </Button> </Tooltip> );}
Composition
For more flexibility, you can use the composition pattern to create a custom tooltip.
composition.tsx
import { Button } from "@/lib/components/core/default/button";import { TooltipRoot, TooltipContent } from "@/lib/components/core/default/tooltip";function Demo() { return ( <TooltipRoot> <Button>Hover</Button> <TooltipContent> <p>Add to library</p> </TooltipContent> </TooltipRoot> );}
API Reference
Tooltip
This component inherits and merges props from TooltipRoot and TooltipContent components.
Prop
Type
Default
Description
content
React.ReactNode
-
The content of the Tooltip
TooltipRoot
Contains all the parts of a tooltip.
Prop
Type
Default
Description
isDisabled
boolean
-
Whether the tooltip should be disabled, independent from the trigger.
delay
number
700
The delay time for the tooltip to show up.
closeDelay
number
0
The delay time for the tooltip to close.
trigger
'focus'
-
By default, opens for both focus and hover. Can be made to open only for focus.
isOpen
boolean
-
Whether the overlay is open by default (controlled).
defaultOpen
boolean
-
Whether the overlay is open by default (uncontrolled).
onOpenChange
(isOpen: boolean) => void
-
Handler that is called when the overlay's open state changes.
TooltipContent
The component that pops out when the tooltip is open.
Prop
Type
Default
Description
triggerRef
boolean
RefObject<Element>
The ref for the element which the tooltip positions itself with respect to. When used within a TooltipTrigger this is set automatically. It is only required when used standalone.
isEntering
boolean
-
Whether the tooltip is currently performing an entry animation.
isExiting
boolean
-
Whether the tooltip is currently performing an exit animation.
placement
Placement
'top'
The placement of the element with respect to its anchor element.
containerPadding
number
12
The placement padding that should be applied between the element and its surrounding container.
offset
number
10
The additional offset applied along the main axis between the element and its anchor element.
crossOffset
number
0
The additional offset applied along the cross axis between the element and its anchor element.
shouldFlip
boolean
true
Whether the element should flip its orientation (e.g. top to bottom or left to right) when there is insufficient room for it to render completely.
isOpen
boolean
-
Whether the element is rendered.
defaultOpen
boolean
-
Whether the overlay is open by default (uncontrolled).
arrowBoundaryOffset
number
-
The minimum distance the arrow's edge should be from the edge of the overlay element.