Components
Tooltip
A short label that appears beside a control while it is hovered or focused.
import { Bookmark } from 'lucide-react'
import { Button } from '@dex/shared/components/button'
import { Tooltip, TooltipContent, TooltipTrigger } from '@dex/shared/components/tooltip'
export function TooltipDefault() {
return (
<Tooltip>
<TooltipTrigger render={<Button variant="outline" size="icon" aria-label="Save role" />}>
<Bookmark />
</TooltipTrigger>
<TooltipContent>Save role</TooltipContent>
</Tooltip>
)
}
import { Button } from '@dex/shared/components/button'
import { Tooltip, TooltipContent, TooltipTrigger } from '@dex/shared/components/tooltip'
const SIDES = ['left', 'top', 'bottom', 'right'] as const
export function TooltipSides() {
return (
<>
{SIDES.map((side) => (
<Tooltip key={side}>
<TooltipTrigger render={<Button variant="outline" className="capitalize" />}>
{side}
</TooltipTrigger>
<TooltipContent side={side}>Posted 3 days ago</TooltipContent>
</Tooltip>
))}
</>
)
}
import { Button } from '@dex/shared/components/button'
import { Tooltip, TooltipContent, TooltipTrigger } from '@dex/shared/components/tooltip'
const ALIGNMENTS = ['start', 'center', 'end'] as const
export function TooltipAlignment() {
return (
<>
{ALIGNMENTS.map((align) => (
<Tooltip key={align}>
<TooltipTrigger render={<Button variant="outline" className="w-40 capitalize" />}>
{align}
</TooltipTrigger>
<TooltipContent align={align}>£120,000 to £140,000</TooltipContent>
</Tooltip>
))}
</>
)
}
import { Button } from '@dex/shared/components/button'
import { Tooltip, TooltipContent, TooltipTrigger } from '@dex/shared/components/tooltip'
export function TooltipOffset() {
return (
<>
<Tooltip>
<TooltipTrigger render={<Button variant="outline" />}>Default</TooltipTrigger>
<TooltipContent>Hybrid, 2 days in the office</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger render={<Button variant="outline" />}>8px further</TooltipTrigger>
<TooltipContent sideOffset={8}>Hybrid, 2 days in the office</TooltipContent>
</Tooltip>
</>
)
}
Notice period:
import { Tooltip, TooltipContent, TooltipTrigger } from '@dex/shared/components/tooltip'
export function TooltipOnText() {
return (
<p className="text-base leading-6">
Notice period:{' '}
<Tooltip>
<TooltipTrigger className="cursor-help underline decoration-dotted underline-offset-4">
3 months
</TooltipTrigger>
<TooltipContent side="bottom">
From your CV. You can change it in your profile.
</TooltipContent>
</Tooltip>
</p>
)
}
- A tooltip opens the moment its trigger is hovered or focused, with no delay. Each
Tooltipbrings its own provider, so it needs nothing above it in the tree. sideistop,bottom,leftorright. The arrow is drawn for those four only.- Near the edge of the screen a tooltip flips to the opposite side, or slides along its trigger and keeps its alignment. The arrow keeps pointing at the centre of the trigger, and hides if it cannot reach it.
- To lift a tooltip above another layer, pass a z-index as
positionerClassName, not inclassName. The positioner is what stacks. - A tooltip on an icon-only button does not replace the button's
aria-label.