Tooltip
Anatomy
Section titled “Anatomy”<TooltipProvider> <Tooltip> <TooltipTrigger /> <TooltipContent /> </Tooltip></TooltipProvider>To display a tooltip, compose <Tooltip>, <TooltipTrigger>, and <TooltipContent>. It default to displaying centered above the trigger and adjust position to avoid colliding with the edge of the viewport. Pressing esc or clicking away will close the tooltip.
import { Button } from "stylus-ui/Button";import { Tooltip, TooltipTrigger, TooltipContent } from "stylus-ui/Tooltip";import { faUserPlus } from "@fortawesome/pro-regular-svg-icons";
export default () => ( <Tooltip> <TooltipTrigger asChild> <Button icon={faUserPlus} variant="secondary" /> </TooltipTrigger> <TooltipContent>Add user</TooltipContent> </Tooltip>);When text is lengthy, it will automatically wrap to multiple lines.
import { Button } from "stylus-ui/Button";import { Tooltip, TooltipTrigger, TooltipContent } from "stylus-ui/Tooltip";
export default () => ( <Tooltip> <TooltipTrigger asChild> <Button variant="secondary">Comment</Button> </TooltipTrigger> <TooltipContent> Collaborative comments are only available for Pro Teams users. Upgrade to add new comments. </TooltipContent> </Tooltip>);Position
Section titled “Position”Tooltips can display on every side of the trigger.
import { Button } from "stylus-ui/Button";import { Tooltip, TooltipTrigger, TooltipContent } from "stylus-ui/Tooltip";import { faArrowLeft, faArrowUp, faArrowDown, faArrowRight,} from "@fortawesome/pro-regular-svg-icons";
export default () => ( <div className="flex items-center gap-1"> <Tooltip> <TooltipTrigger asChild> <Button icon={faArrowLeft} variant="secondary" /> </TooltipTrigger> <TooltipContent side="left">Left</TooltipContent> </Tooltip> <div className="flex flex-col gap-1"> <Tooltip> <TooltipTrigger asChild> <Button icon={faArrowUp} variant="secondary" /> </TooltipTrigger> <TooltipContent side="top">Top</TooltipContent> </Tooltip> <Tooltip> <TooltipTrigger asChild> <Button icon={faArrowDown} variant="secondary" /> </TooltipTrigger> <TooltipContent side="bottom">Bottom</TooltipContent> </Tooltip> </div> <Tooltip> <TooltipTrigger asChild> <Button icon={faArrowRight} variant="secondary" /> </TooltipTrigger> <TooltipContent side="right">Right</TooltipContent> </Tooltip> </div>);Use the delayDuration prop to control the time it takes for the tooltip to open.
import { Button } from "stylus-ui/Button";import { Tooltip, TooltipTrigger, TooltipContent } from "stylus-ui/Tooltip";import { faUserPlus } from "@fortawesome/pro-regular-svg-icons";
export default () => ( // Display tooltip instantly <Tooltip delayDuration={0}> <TooltipTrigger asChild> <Button icon={faUserPlus} variant="secondary" /> </TooltipTrigger> <TooltipContent>Add user</TooltipContent> </Tooltip>);API Reference
Section titled “API Reference”TooltipProvider
Section titled “TooltipProvider” delayDuration
The duration from when the pointer enters the trigger until the tooltip gets opened.
disableHoverableContent
When true, trying to hover the content will result in the tooltip closing as the pointer leaves the trigger.
skipDelayDuration
How much time a user has to enter another trigger without incurring a delay again.
Tooltip
Section titled “Tooltip”A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.
defaultOpen
delayDuration
The duration from when the pointer enters the trigger until the tooltip gets opened. This will override the prop with the same name passed to Provider.
disableHoverableContent
When true, trying to hover the content will result in the tooltip closing as the pointer leaves the trigger.
onOpenChange
open
TooltipTrigger
Section titled “TooltipTrigger” asChild
TooltipContent
Section titled “TooltipContent” align
alignOffset
aria-label
A more descriptive label for accessibility purpose
arrowPadding
asChild
avoidCollisions
collisionBoundary
collisionPadding
forceMount
Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
hideWhenDetached
onEscapeKeyDown
Event handler called when the escape key is down. Can be prevented.
onPointerDownOutside
Event handler called when the a pointerdown event happens outside of the Tooltip.
Can be prevented.
side
sideOffset
sticky
updatePositionStrategy
TooltipPortal
Section titled “TooltipPortal” container
Specify a container element to portal the content into.
forceMount
Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.