ComponentesComponents

Tooltip

Etiqueta breve al pasar el ratón o enfocar.Short label on hover or focus.

DiseñoDesign: coss ui (MIT) · tooltip.tsxMITambos · densidaddensity media · sobriaMarkdownJSON

CódigoCode

<div class="c-tooltip-row">
  <button class="c-btn c-btn--outline c-btn--icon" type="button" aria-label="Negrita" aria-describedby="tip-bold" data-c-tooltip="tip-bold">
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8"/></svg>
  </button>
  <button class="c-btn c-btn--outline c-btn--icon" type="button" aria-label="Cursiva" aria-describedby="tip-italic" data-c-tooltip="tip-italic">
    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 4h-9"/><path d="M14 20H5"/><path d="M15 4 9 20"/></svg>
  </button>
  <button class="c-btn c-btn--outline" type="button" aria-describedby="tip-save" data-c-tooltip="tip-save">Guardar</button>
</div>
<div class="c-tooltip" id="tip-bold" role="tooltip" popover="manual">Negrita · ⌘B</div>
<div class="c-tooltip" id="tip-italic" role="tooltip" popover="manual">Cursiva · ⌘I</div>
<div class="c-tooltip" id="tip-save" role="tooltip" popover="manual">Se guarda en tu navegador</div>

«Todo» trae tokens, dependencias y componente en un solo archivo, listo para abrir o dárselo a un agente.“All” bundles tokens, dependencies and the component in one file, ready to open or hand to an agent.

InstalaciónInstallation

  1. Agrega una vezAdd once tokens.css (colores, radios, tema oscuro).(colors, radii, dark theme).
  2. Agrega también:Also add: BotónButton.
  3. Copia los archivos:Copy the files: tooltip.html, tooltip.css, tooltip.js.
  4. Para el tema oscuro, pon la claseFor the dark theme, add the class dark ento <html>.

Cuándo usarloWhen to use it

ÚsaloUse it

  • Para nombrar botones con icono o dar un atajo.
  • To name icon buttons or show a shortcut.

Mejor noAvoid

  • Para información importante: en pantallas táctiles no hay hover.
  • For important information: touch screens have no hover.

AccesibilidadAccessibility

tooltip
TabMuestra el tooltip al enfocarShows the tooltip on focus
EscLo ocultaHides it
  • El texto también va en aria-describedby.
  • Se puede pasar el ratón encima sin que desaparezca (WCAG 1.4.13).
  • The text is also in aria-describedby.
  • You can hover the tooltip without it disappearing (WCAG 1.4.13).

Cómo probarloHow to test it

  • Enfoca «Negrita» con Tab: aparece «Negrita · ⌘B»; Esc lo oculta.
  • Tab to “Bold”: “Bold · ⌘B” appears; Esc hides it.

CréditosCredits