30/Overlays
Tooltip and popover
Text tooltip on hover and focus, and popover with interactive content that opens on click.
Tooltip
Use data-cb-tooltip-placement to choose the side; if it does not fit, it flips automatically.
HTML
<button class="cb-btn cb-btn--outline" type="button" data-cb-tooltip="Guarda los cambios (⌘S)">Arriba</button>
<button class="cb-btn cb-btn--outline" type="button" data-cb-tooltip="Aparece abajo" data-cb-tooltip-placement="bottom">Abajo</button>
<button class="cb-btn cb-btn--outline" type="button" data-cb-tooltip="A la derecha" data-cb-tooltip-placement="right">Derecha</button>
<button class="cb-icon-btn" type="button" aria-label="Información" data-cb-tooltip="El NIT debe incluir el guion"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 11v5M12 8h.01"/></svg></button>
Popover
Compartir enlace
Cualquiera con el enlace podrá verlo.
HTML
<div class="cb-popover self-start" data-cb-popover>
<button class="cb-btn cb-btn--outline" type="button">Compartir</button>
<div class="cb-popover__panel" aria-label="Compartir enlace">
<p class="cb-popover__title">Compartir enlace</p>
<p class="mb-3">Cualquiera con el enlace podrá verlo.</p>
<div class="cb-input-group"><input class="cb-input cb-input--sm" value="https://ejemplo.com/p/42" aria-label="Enlace" readonly><button class="cb-btn cb-btn--primary cb-btn--sm" type="button" data-cb-copy="https://ejemplo.com/p/42"><span data-cb-copy-label>Copiar</span></button></div>
</div>
</div>
Classes and modifiers
| Class | Description |
|---|---|
.cb-tooltip | Text bubble that the JS creates in the body. |
.cb-popover, .cb-popover__panel | Container and panel. --end aligns to the right. |
.cb-popover__title | Panel title. |
data-cb-* attributes
| Attribute | Description |
|---|---|
data-cb-tooltip="texto" | Tooltip text. |
data-cb-tooltip-placement="top|bottom|left|right" | Preferred side. |
data-cb-popover | Enables the popover. |
data-cb-popover-trigger | Button that opens it (by default, the first button). |
JavaScript
| Event | When it fires |
|---|---|
cb:open / cb:close | On the popover when it opens or closes. |
Accessibility
- The tooltip is linked with
aria-describedbywhile visible and closes with Esc (WCAG 1.4.13). - Do not put essential information only in a tooltip: it is not visible on touch screens.
- The popover panel has
role="dialog"and the button hasaria-expanded.