# Tooltip

A short label that appears beside a control while it is hovered or focused.

This is the HTML to build it with `dex.css`, for work outside the Dex codebase. Read https://brand.meetdex.ai/design.md first: it says how to set up a page and how to use the stylesheet. The page at https://brand.meetdex.ai/components/tooltip shows the Dex app's own React component, which only works inside the Dex codebase.

## HTML

`dex-tooltip` draws the label: a foreground fill with background text. `dex.css` doesn't place it or show it on hover, so do both with a few lines of CSS of your own, inside a `dex-popover-anchor`:

```html
<style>
  .tip > .dex-tooltip {
    position: absolute;
    bottom: calc(100% + 0.25rem);
    left: 50%;
    z-index: 50;
    transform: translateX(-50%);
    white-space: nowrap;
    pointer-events: none;
    visibility: hidden;
  }
  .tip:is(:hover, :focus-within) > .dex-tooltip {
    visibility: visible;
  }
</style>

<span class="dex-popover-anchor tip">
  <button class="dex-button dex-button--ghost dex-button--sm" style="width: 2rem; padding: 0" aria-label="Copy link" aria-describedby="copy-tip">
    <svg aria-hidden="true"><!-- Lucide link --></svg>
  </button>
  <span class="dex-tooltip" role="tooltip" id="copy-tip">Copy link</span>
</span>
```

- **Sides**: above by default. For below, `top: calc(100% + 0.25rem)` in place of `bottom`; for the left or right, `right: calc(100% + 0.25rem)` or `left: calc(100% + 0.25rem)` with `top: 50%; transform: translateY(-50%)`.
- **On text**: make the trigger a `<button>` round the words, so it can be reached with the keyboard wherever it sits.
- **A shortcut in it**: a `dex-kbd` inside the tooltip takes the tooltip's colours (`Search <kbd class="dex-kbd">⌘K</kbd>`).
- **The arrow**: the app's tooltip has a small arrow pointing at its trigger. `dex.css` doesn't draw one; leave it out.

## Rules

- A tooltip opens the moment its trigger is hovered or focused, with no delay, and closes when it isn't.
- A few words only, in sentence case with no full stop. Nothing in it can be pressed.
- A tooltip on an icon-only button doesn't replace the button's `aria-label`.
- Near the edge of the screen, open it on another side so it stays in view.
