A React tooltip component from Radix UI Primitives, part of an open-source UI component library for building high-quality, accessible design systems and web apps
Overall
score
96%
The TooltipArrow component provides a visual arrow/pointer that connects the tooltip content to its trigger, enhancing the visual relationship and user experience.
Optional arrow component that renders as an SVG element pointing from tooltip content toward the trigger.
/**
* Arrow/pointer component for tooltips
* Renders as SVG element that points from content to trigger
* @param width - Width of arrow in pixels
* @param height - Height of arrow in pixels
* @param offset - Offset from content edge in pixels
*/
type TooltipArrowElement = React.ComponentRef<"svg">;
interface TooltipArrowProps extends React.ComponentPropsWithoutRef<"svg"> {
width?: number;
height?: number;
offset?: number;
}
const TooltipArrow: React.forwardRef<TooltipArrowElement, TooltipArrowProps>;Usage Examples:
import {
TooltipProvider,
Tooltip,
TooltipTrigger,
TooltipPortal,
TooltipContent,
TooltipArrow
} from "@radix-ui/react-tooltip";
// Basic arrow
function BasicArrowTooltip() {
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger>Hover me</TooltipTrigger>
<TooltipPortal>
<TooltipContent>
Tooltip with arrow
<TooltipArrow />
</TooltipContent>
</TooltipPortal>
</Tooltip>
</TooltipProvider>
);
}
// Custom sized arrow
function CustomArrow() {
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger>Hover me</TooltipTrigger>
<TooltipPortal>
<TooltipContent>
Large arrow tooltip
<TooltipArrow width={15} height={10} />
</TooltipContent>
</TooltipPortal>
</Tooltip>
</TooltipProvider>
);
}
// Styled arrow
function StyledArrow() {
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger>Hover me</TooltipTrigger>
<TooltipPortal>
<TooltipContent className="custom-tooltip">
Styled tooltip
<TooltipArrow
className="custom-arrow"
fill="var(--tooltip-background)"
stroke="var(--tooltip-border)"
strokeWidth={1}
/>
</TooltipContent>
</TooltipPortal>
</Tooltip>
</TooltipProvider>
);
}
// Arrow with offset
function OffsetArrow() {
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger>Hover me</TooltipTrigger>
<TooltipPortal>
<TooltipContent>
Arrow with offset
<TooltipArrow offset={10} />
</TooltipContent>
</TooltipPortal>
</Tooltip>
</TooltipProvider>
);
}Controls the width of the arrow.
number10 pixelsControls the height of the arrow.
number5 pixelsControls the offset from the content edge.
number0 pixelsArrow accepts all standard SVG props for styling:
string - Fill color of the arrowstring - Stroke color of the arrownumber - Width of arrow strokestring - CSS class for stylingReact.CSSProperties - Inline stylesThe arrow automatically positions itself based on:
arrowPadding prop on TooltipContentThe arrow renders as a simple filled triangle with:
/* Style the arrow */
.custom-arrow {
fill: #333;
stroke: #666;
stroke-width: 1px;
}
/* Style based on tooltip side */
.tooltip-content[data-side="top"] .arrow {
fill: var(--tooltip-bg-top);
}
.tooltip-content[data-side="bottom"] .arrow {
fill: var(--tooltip-bg-bottom);
}Arrow inherits CSS custom properties from content:
--radix-tooltip-content-transform-originArrow automatically orients based on tooltip placement:
When tooltip content repositions due to collisions:
The arrow is purely decorative and:
const Arrow: React.forwardRef<TooltipArrowElement, TooltipArrowProps>;The Arrow component is an alias for TooltipArrow for shorter import names.
type TooltipArrowElement = React.ComponentRef<"svg">;
type TooltipArrowProps = React.ComponentPropsWithoutRef<"svg"> & {
width?: number;
height?: number;
offset?: number;
};Install with Tessl CLI
npx tessl i tessl/npm-radix-ui--react-tooltipevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10