# Context menu

A menu that opens where the pointer is, on a right-click or a long press.

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/context-menu shows the Dex app's own React component, which only works inside the Dex codebase.

## HTML

The same `dex-menu` as the dropdown menu (https://brand.meetdex.ai/components/dropdown-menu.md), placed at the pointer with a little script:

```html
<div id="logo-area"><span class="dex-logo" style="width: 6rem"></span></div>

<div class="dex-menu" id="logo-menu" role="menu" hidden style="position: fixed; z-index: 50">
  <button class="dex-menu-item" role="menuitem">Copy logo as SVG</button>
  <button class="dex-menu-item" role="menuitem">Download logo files</button>
</div>

<script>
  const area = document.getElementById('logo-area')
  const menu = document.getElementById('logo-menu')
  area.addEventListener('contextmenu', (event) => {
    event.preventDefault()
    menu.style.left = `${event.clientX}px`
    menu.style.top = `${event.clientY}px`
    menu.hidden = false
    menu.querySelector('[role="menuitem"]').focus()
  })
  document.addEventListener('click', () => (menu.hidden = true))
  document.addEventListener('keydown', (event) => {
    if (event.key === 'Escape') menu.hidden = true
  })
</script>
```

- **With a choice**: `role="menuitemradio"` items with `aria-checked="true"` on the chosen one, which gets the tick.

## Rules

- Nothing on the page shows a context menu is there, and a touch screen without long press never opens it. So it only offers shortcuts to things the page already does elsewhere, or small extras such as copying the logo, never the only way to do something.
- Keep it short: the few things someone is likely to want from that spot, most likely first.
- Its items, separators, labels and choices follow the dropdown menu's rules.
- A destructive item goes last, after a separator.
