Feedback

Tooltip

A little extra context on hover or keyboard focus.

OSCL StudioComponents, in context.Live preview
FOUNDATION / FEEDBACK

Tooltip

Interactive preview. Real components.View docs

Use it in your project

Install oscl-ui from npm and import oscl-ui/styles.css once. See installation.

tooltip-example.tsx
import { Tooltip, Button } from "oscl-ui";

<Tooltip content="Save your changes">
  <Button variant="outline">Save</Button>
</Tooltip>

Accessibility

Keep visible labels and keyboard focus. Supply an accessible name to icon-only actions. Try this preview with Tab, Enter, Space, and Escape where appropriate.

The source, in full

This is the actual source from the isolated OSCL package used by this website. Native props and TypeScript declarations are included in the npm package.

tooltip.tsx
"use client";

import * as Primitive from "@radix-ui/react-tooltip";
import type { ReactElement, ReactNode } from "react";

export interface TooltipProps {
  children: ReactElement;
  content: ReactNode;
  delayDuration?: number;
  side?: "top" | "right" | "bottom" | "left";
  theme?: "light" | "dark";
  className?: string;
}
export function Tooltip({ children, content, delayDuration = 400, side = "top", theme, className = "" }: TooltipProps) {
  return <Primitive.Provider delayDuration={delayDuration}><Primitive.Root>
    <Primitive.Trigger asChild>{children}</Primitive.Trigger>
    <Primitive.Portal><Primitive.Content side={side} sideOffset={8} data-oscl-theme={theme} className={`oscl-tooltip ${className}`}>
      {content}<Primitive.Arrow className="oscl-tooltip-arrow" />
    </Primitive.Content></Primitive.Portal>
  </Primitive.Root></Primitive.Provider>;
}