# Tooltip Button

A button, usually icon-only, whose tooltip also gives it an accessible name.

Page: https://sui.draco.dev/docs/components/tooltip-button

### Example: tooltip-button-demo

```tsx
"use client";
import { TooltipButton } from "@workspace/ui/components/tooltip-button";
import { Bold, Italic, Underline } from "lucide-react";
import type { ExampleProps } from "../types";

export default function Example({ locale }: ExampleProps) {
  const chinese = locale === "zh-CN";
  return (
    <div className="flex gap-1">
      <TooltipButton
        variant="ghost"
        size="icon-sm"
        tooltip={chinese ? "加粗" : "Bold"}
      >
        <Bold />
      </TooltipButton>
      <TooltipButton
        variant="ghost"
        size="icon-sm"
        tooltip={chinese ? "斜体" : "Italic"}
      >
        <Italic />
      </TooltipButton>
      <TooltipButton
        variant="ghost"
        size="icon-sm"
        tooltip={chinese ? "下划线" : "Underline"}
      >
        <Underline />
      </TooltipButton>
    </div>
  );
}
```

## Installation

```bash
npx shadcn@latest add @sui/tooltip-button
```

With pnpm, Yarn or Bun, use `pnpm dlx`, `yarn dlx` or `bunx --bun` in place of `npx`, and `pnpm add`, `yarn add` or `bun add` in place of `npm install`.

Install with the shadcn CLI or use the shared `@workspace/ui` package. Follow the [installation guide](/docs/installation) to configure the registry, load styles, and choose import aliases.

```tsx
import { TooltipButton } from "@workspace/ui/components/tooltip-button";
```

## Usage

```tsx
<TooltipButton variant="ghost" size="icon-sm" tooltip="Bold">
  <Bold />
</TooltipButton>
```

`tooltip` is shown on hover and focus through [Tooltip](/docs/components/tooltip) and is also the button's `aria-label`, so icon-only buttons are named once. All other [Button](/docs/components/button) props pass through, including `glass`. Toolbars in [Code Editor](/docs/components/code-editor) and the [Image](/docs/components/image) preview are built from it.

## API reference

| Prop | Type | Default / behavior |
| --- | --- | --- |
| `tooltip` | `string` | Required; tooltip text and accessible name. |
| Button props | | Passed to the Button. |

The module exports `TooltipButtonProps`.
