Skip to main content

Tooltip

Displays contextual information on hover, focus, or click.

Package@g4rcez/componentsSectionFloating Elements

Examples

Basic Tooltips and Interactions

Demonstrates tooltips with various triggers (hover, click, disabled) and cursor-following behavior.

tsx
"use client";
import { useState } from "react";
import { Button, Card, negate, Tooltip } from "@g4rcez/components";

function BasicTooltips() {
  const ClickControlled = () => {
    const [open, setOpen] = useState(true);
    const toggle = () => setOpen(negate);
    return (
      <div className="flex gap-2 items-center border border-card-border px-4 w-fit">
        <Tooltip
          as={Button}
          open={open}
          focus={false}
          hover={false}
          title="Controlled"
        >
          <div className="flex flex-col gap-4">Controlled</div>
        </Tooltip>
        <Button onClick={toggle} theme="muted">
          {open ? "Close" : "Open"}
        </Button>
      </div>
    );
  };

  return (
    <Card className="flex flex-row flex-wrap gap-4">
      <Tooltip as={Button} title="Hover me" followCursor>
        Mouse follows you
      </Tooltip>
      <Tooltip
        hover={false}
        popover={true}
        as={Button}
        title="Only click"
        followCursor
      >
        Mouse follows you
      </Tooltip>
      <Tooltip
        enabled={false}
        as={Button}
        disabled
        title="Disabled"
        followCursor
      >
        Mouse follows you
      </Tooltip>
      <ClickControlled />
    </Card>
  );
}

When to use Tooltip

Use when

You need the documented Tooltip interaction or presentation in a product workflow.

Avoid when

A native HTML element already provides the Tooltip behavior you need.

Accessibility

Keep the Tooltip labeled and use its documented keyboard interaction. The component preserves visible focus and communicates state without relying on color alone.

  • Keep keyboard focus visible and follow the documented key commands.
  • Provide an accessible name and connect descriptions or errors to the control.