ComponentesComponents

Menú desplegableDropdown menu

Lista de acciones que se abre desde un botón.List of actions opened from a button.

DiseñoDesign: coss ui (MIT) · menu.tsxMITherramienta · densidaddensity media · sobriaMarkdownJSON

CódigoCode

<button class="c-btn c-btn--outline" type="button" id="menu-trigger" aria-haspopup="menu" aria-expanded="false" aria-controls="menu-actions" data-c-menu>
  Acciones
  <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 9 6 6 6-6"/></svg>
</button>
<div class="c-menu__popup" id="menu-actions" popover role="menu" aria-labelledby="menu-trigger">
  <div class="c-menu__list">
    <div class="c-menu__label" role="presentation">Proyecto</div>
    <button class="c-menu__item" role="menuitem" type="button" tabindex="-1">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 20h9"/><path d="M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z"/></svg>
      Editar <span class="c-menu__shortcut" aria-hidden="true">⌘E</span>
    </button>
    <button class="c-menu__item" role="menuitem" type="button" tabindex="-1">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect width="14" height="14" x="8" y="8" rx="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></svg>
      Duplicar <span class="c-menu__shortcut" aria-hidden="true">⌘D</span>
    </button>
    <button class="c-menu__item" role="menuitem" type="button" tabindex="-1" aria-disabled="true">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><path d="m16 6-4-4-4 4"/><path d="M12 2v13"/></svg>
      Compartir
    </button>
    <div class="c-menu__separator" role="separator"></div>
    <button class="c-menu__item" role="menuitem" type="button" tabindex="-1" data-variant="destructive">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/></svg>
      Eliminar
    </button>
  </div>
</div>
<p class="c-sr-only" role="status" data-c-menu-status></p>

«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: menu.html, menu.css, menu.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 acciones secundarias sobre un elemento.
  • For secondary actions on an item.

Mejor noAvoid

  • Para navegar entre páginas: usa enlaces.
  • Para elegir un valor: usa select.
  • To navigate between pages: use links.
  • To pick a value: use a select.

AccesibilidadAccessibility

buttonmenumenuitem
Enter ↓Abre y enfoca la primera acciónOpens and focuses the first action
↑ ↓Recorre las accionesMoves through actions
EscCierra y vuelve al botónCloses and returns to the button
Letra LetterSalta a la acciónJumps to the action
  • Patrón «menu button» de la W3C sobre popover nativo (capa superior y clic fuera).
  • Las acciones deshabilitadas se saltan con las flechas.
  • W3C “menu button” pattern over a native popover (top layer and outside click).
  • Disabled actions are skipped with the arrows.

Cómo probarloHow to test it

  • Abre con Enter, baja con ↓ y cierra con Esc: el foco vuelve a «Acciones».
  • Open with Enter, move with ↓, close with Esc: focus returns to “Actions”.

CréditosCredits