Tooltip
Usage
Peer Dependencies
Properties
Tooltip Inline
In the world of modern technology, staying updated is no longer optional—it’s a necessity. Innovations in artificial intelligence have reshaped how we interact with systems, enabling a more personalized and efficient experience. Yet, with rapid advancements come challenges. Developers must navigate the complexities of scalability, ensuring applications grow seamlessly without compromising performance. Similarly, the rise of cybersecurity concerns has pushed teams to prioritize safeguarding user data while maintaining accessibility. Every step forward in this digital age is an opportunity to create impactful solutions, but it also demands a commitment to learning, adapting, and overcoming.
Anatomy
Tooltip requires a trigger as an content
anchors, you can provide children strings, fragments, numbers, and several elements/components which will later be wrapped in a <button>
.
In contrast, when you use asChild
props, use an element or component as a single child – providing strings, fragments, numbers, and multiple elements/components will cause errors.
The content
property is ReactNode
, its will pass children to the tooltip content. Use contentProps
to change style, attributes, and pass all properties to the content body.
Alternative
You can use several ways to use Tooltip.
- Using with
TooltipProvider
andOrigin/Trees
Tooltip will provide full flexibility in customization.
export function MyToggle() {
return (
<TooltipProvider>
<TooltipTrigger asChild>
<button>
<BrandGithubFillIcon className="size-5" />
</button>
</TooltipTrigger>
<TooltipContent side="left" sideOffset={6} className="min-w-[86px]">
<span>Lorem...</span>
</TooltipContent>
</TooltipProvider>
);
}
- Using inline components will make your writing more concise.
- without
asChild
property
export function MyToggle() {
return (
<Tooltip side="left" sideOffset={6} content="React.ReactNode">
Button
</Tooltip>
);
}
- with asChild property
export function MyToggle() {
return (
<Tooltip asChild side="left" sideOffset={6} content={<span>Lorem...</span>}>
<a href="">
<Icon className="size-5" />
</a>
</Tooltip>
);
}
- Using ref in the trigger component.
export const MyToggle = React.forwardRef<React.ElementRef<"a">, React.ComponentPropsWithoutRef<"a">>(({ ...props }, ref) => {
return (
<Tooltip asChild side="left" sideOffset={6} content={<span>Lorem...</span>}>
<a ref={ref} href="">
<Icon className="size-5" />
</a>
</Tooltip>
);
});
MyToggle.displayName = "MyToggle";
API References
Styles API
Styles API | Type | Default | Annotation |
---|---|---|---|
unstyled? | boolean | false | if true , all default styles will be removed |
Tooltip API
Props API Tooltip | Type | Default | Annotation |
---|---|---|---|
asChild? | false | - | pass the triggerRef props to an element or component as a single child |
content? | React.ReactNode | null | pass children to TooltipContent as React.ReactNode |
contentProps? | DetailedHTMLProps Content | "div" | pass all attribute TooltipContent |
open? | boolean | false | change the original open and onOpenChange state with own approach |
onOpenChange? | (value: boolean) => void | openState | change the original open and onOpenChange state with own approach |
sideOffset? | number | 0 | distance between TooltipTrigger and TooltipContent |
withArrow? | boolean | false | add arrow on TooltipContent |
touch? | boolean | false | allows TooltipContent to open when receiving a touch |
align? | "center" | "start" | "end" | "center" | only available on "dropdown" variant |
side? | "top" | "right" | "bottom" | "left" | "bottom" | only available on ["dropdown", "drawer"] variant |
TooltipTrigger API
Props API TooltipTrigger | Type | Default | Annotation |
---|---|---|---|
asChild? | false | - | pass the triggerRef props to an element or component as a single child |