Tooltip
Tooltip acrescenta uma dica curta a um controle que já tem nome. Decida antes se a dica não deveria ser texto visível — um tooltip é o lugar mais frágil para pôr qualquer coisa que a pessoa precise ler.
Exemplos
Num botão
Passe um elemento focável como filho. O componente adiciona aria-describedby a ele, então a dica
chega a quem usa teclado e leitor de tela, não só ao mouse.
Em controles só de ícone
O label do icon button é o nome dele; o tooltip é a frase extra. São funções diferentes, e um
tooltip nunca pode ser o único lugar onde o nome de um controle existe.
Inside scrolling navigation
Set escapeClipping to keep a hint visible beyond an overflow or scroll container. Try the icons,
scroll the rail, and switch its scoped theme or direction. The hint stays within the visual
viewport.
Hover or focus an icon, then scroll this clipped navigation.
Selected: Overview
Quando usar
Use Tooltip para esclarecer brevemente um controle cujo propósito já é comunicado pelo próprio nome ou ícone.
Procure outra coisa quando:
- O texto é o nome do controle — use o
labeldoIconButton, ou um rótulo visível. - The content is long, or contains a link or a button — tooltips are brief, non-interactive hints. Use Dialog or inline copy.
- A informação importa no toque — ali não existe hover, e um tooltip que só abre no foco é fácil de nunca ver.
Acessibilidade
- By default, CSS draws the visible bubble from
data-tip; a separate hidden<span role="tooltip">supplies the accessible description. The open React bubble accepts pointer hits, so moving from the target onto the hint keeps it open during the existing leave grace. - With
escapeClipping={true}, a real, non-focusable<span role="tooltip">enters the browser's top layer. It remains inside the wrapper in the DOM, preserving scoped theme, brand tokens, fonts and direction, including changes while open. It wraps long labels and clamps its bounds to the visual viewport. Both modes mergearia-describedbywith your child's existing description. - The clipping-safe mode can use another side or a shorter scrolling hint to keep its target reachable.
tipremains a plain string: neither mode supports interactive content or moves focus into the hint.- Abre no hover e no foco.
Escapedispensa sem mover o ponteiro — é exatamente o que a WCAG 1.4.13 pede de conteúdo mostrado no hover, e o listener fica no documento, porque uma dica aberta por hover nunca tem foco dentro dela para receber a tecla. placementescolhe o lado (toppor padrão). É uma preferência, não uma garantia: a dica vira para o lado oposto sozinha quando o escolhido seria cortado, medindo contra ovisualViewportpara que a barra do iOS ou o zoom de pinça não façam uma dica fora da tela parecer que cabe.- Passe um elemento focável. Embrulhar um
<span>puro produz um tooltip só de mouse, sem caminho de teclado até ele. - No App Router do Next.js, mantenha o Tooltip e o filho dele no mesmo client component. O
aria-describedbyé adicionado clonando o seu elemento, e um filho que cruza a fronteira servidor/cliente chega já serializado: o atributo some do HTML do servidor, o React acusa divergência de hidratação e — como ele não corrige divergência de atributo — a descrição nunca chega ao DOM. Um'use client'no arquivo que renderiza os dois resolve.
API e código
| Nome | Tipo | Obrigatória | Descrição |
|---|---|---|---|
tip | string | Obrigatória | Short, non-interactive text shown for the target. |
children | ReactNode | Obrigatória | The target element. Pass one focusable React element for full keyboard support. |
placement | TooltipPlacement | — | Side of the target to draw the tip on. Default `"top"`. The tip flips to the opposite side on its own when the chosen one would be clipped by the viewport, so this is a preference. Clipping escape can use another side or limit the hint's height to keep the target reachable. |
escapeClipping | boolean | — | Escape overflow and scroll clipping while keeping the hint inside the visual viewport. Default `false`. |
escapeClipping is opt-in and defaults to false. The default keeps the existing CSS-drawn markup
and behavior; the public ref still targets the wrapper span in both modes. Use the opt-in for scroll
or overflow ancestors: a higher z-index alone cannot escape their clipping. Opening and closing use
the same delays, hover transit, focus handling and Escape arbitration. This is a React capability;
canonical HTML, Alpine and Blade contracts are unchanged.
x-data="lyraTooltip({ … })"
| Opção | Tipo | Obrigatória | Descrição |
|---|---|---|---|
tip | string | Obrigatória | Short, non-interactive text shown for the target. |
placement | TooltipPlacement | — | Preferred side of the target. Default: `"top"`. |
O wrapper carrega o texto em data-tip; o CSS desenha a bolha a partir dele:
<span class="lyra-tooltip" data-tip="Todos no workspace conseguem abrir este link">
<button
class="lyra-btn lyra-btn--secondary lyra-btn--md"
type="button"
aria-describedby="tip-share"
>
Copiar link de compartilhamento
</button>
<span id="tip-share" role="tooltip" hidden>Todos no workspace conseguem abrir este link</span>
</span><lyra:tooltip> Gerado do lyra-ds/blade v0.10.0.
O comportamento vem de lyraTooltip() — instale @lyra-ds/alpine e veja a aba HTML + Alpine.
| Prop | Padrão | Obrigatória | Valores de exemplo |
|---|---|---|---|
tip | — | Obrigatória | — |
placement | 'top' | — | bottom |
<lyra:tooltip tip="Deploys the current branch to production" placement="top">
<lyra:button variant="primary" size="sm">Deploy</lyra:button>
</lyra:tooltip>