Tooltip
Tooltip whose bubble grows out of its arrow pixel by pixel on hover or keyboard focus before the text fades in; Escape hides it.
Playground
Change a prop and the component re-renders. Props marked remounts set an initial value, so the component starts over.
<PxTooltip content="Copy link" placement="top" delay={250}>Hover me</PxTooltip>Installation
pnpm dlx shadcn@latest add @lumesec/px-tooltipFirst timeRegister the @lumesec registry once, or install by URL
Adds @lumesec to your components.json:
pnpm dlx shadcn@latest registry add @lumesec=https://elements.lumesec.ai/r/{name}.jsonOr skip the setup and install by URL:
npx shadcn@latest add https://elements.lumesec.ai/r/px-tooltip.jsonUsage
import { PxTooltip } from "@/components/lumesec/px-tooltip";
export function Example() {
return (
<PxTooltip content="Copy link">
<button type="button">Copy</button>
</PxTooltip>
);
}Behaviour
The bubble grows out of its arrow pixel by pixel on hover or keyboard focus, then the text fades in. Escape hides it.
API reference
Props
Also accepts every prop of <span> (React.ComponentProps<"span">), spread onto the root element.
contentTypeReact.ReactNodeTooltip text. It does not wrap.
childrenTypeReact.ReactNodeThe trigger, usually a button. A single element gets aria-describedby pointing at the tooltip.
placementType"top" | "bottom"Default"top"Preferred side: bottom places the bubble below the trigger. It flips to the other side when this one has no room in the viewport.
delayTypenumberDefault250Milliseconds of hover or focus before the bubble opens.
openTypebooleanControlled open state. Use with onOpenChange.
defaultOpenTypebooleanDefaultfalseInitial open state when uncontrolled.
onOpenChangeType(open: boolean) => voidCalled when hover, focus or Escape opens or closes the tooltip.
Ref
ref points at the root HTMLSpanElement.
Keyboard
| Keys | Action |
|---|---|
| Escape | Hide the tooltip, wherever focus is. |
Accessibility
- The bubble has
role="tooltip"and stays in the DOM (hidden when closed); the trigger references it witharia-describedby, merged with any value the trigger already has. - It opens on keyboard focus as well as hover, and closes 60 ms after focus or the pointer leaves.
- The bubble does not take pointer events.
- Reduced motion: the bubble appears at full size at once instead of growing from the arrow.
Theming
Styled with Tailwind classes on your shadcn theme tokens, so light and dark follow your theme. The accent comes from --lumesec. See Theming.
This component reads --foreground, --muted and --card.
Notes
- The bubble is centred on the trigger and does not wrap its text. When it opens it flips to the other side if its own side has no room in the viewport and the other side has, and moves sideways to stay 8 px inside the viewport; the arrow keeps pointing at the trigger. It is placed once per opening and does not follow scrolling.
- The root is an inline-block
spanaround the trigger. Pointer and focus handlers passed to it run first; callingevent.preventDefault()in one skips the tooltip's own handling of that event. - The bubble carries
data-sidewith the side it opened on.
Related
Was this page helpful?