Skip to content
MarkasUI
Type to search

    Guide

    MarkasUI

    Form

    Feedback

    Overlay

    Navigation

    Data

    Sections

    Animations

    Backgrounds

    Buttons

    Templates

    Pages

    Context Menu

    Menu opened by right-clicking an area or pressing Shift+F10, shown at the pointer through the Popover API with WAI-ARIA Menu keyboard support.

    Right-click here
    Press Shift+F10 to open the context menu
    Right-click here
    Press Shift+F10 to open the context menu
    Right-click here
    Press Shift+F10 to open the context menu
    Right-click here
    Press Shift+F10 to open the context menu
    Right-click here
    Press Shift+F10 to open the context menu
    <x-markas.context-menu
        :items="[
            ['label' => 'Open', 'value' => 'open'],
            ['label' => 'Rename', 'value' => 'rename'],
            ['label' => 'Duplicate', 'value' => 'duplicate'],
            ['label' => 'Archive', 'value' => 'archive', 'disabled' => true],
            ['separator' => true],
            ['label' => 'Delete', 'value' => 'delete', 'danger' => true],
        ]"
    >
        <div class="flex h-36 items-center justify-center rounded-lg border border-dashed border-line text-sm text-muted">Right-click here</div>
    </x-markas.context-menu>
    import { ContextMenu } from "@/components/markas/ContextMenu";
    
    const items = [
      { label: "Open", value: "open" },
      { label: "Rename", value: "rename" },
      { label: "Duplicate", value: "duplicate" },
      { label: "Archive", value: "archive", disabled: true },
      { separator: true as const },
      { label: "Delete", value: "delete", danger: true },
    ];
    
    export default function ContextMenuExample() {
      return (
        <ContextMenu items={items}>
          <div className="flex h-36 items-center justify-center rounded-lg border border-dashed border-line text-sm text-muted">
            Right-click here
          </div>
        </ContextMenu>
      );
    }
    <script setup lang="ts">
    import ContextMenu from "@/components/markas/ContextMenu.vue";
    
    const items = [
      { label: "Open", value: "open" },
      { label: "Rename", value: "rename" },
      { label: "Duplicate", value: "duplicate" },
      { label: "Archive", value: "archive", disabled: true },
      { separator: true as const },
      { label: "Delete", value: "delete", danger: true },
    ];
    </script>
    
    <template>
      <ContextMenu :items="items">
        <div
          class="flex h-36 items-center justify-center rounded-lg border border-dashed border-line text-sm text-muted"
        >
          Right-click here
        </div>
      </ContextMenu>
    </template>
    <script lang="ts">
      import ContextMenu from "$lib/components/markas/ContextMenu.svelte";
    
      const items = [
        { label: "Open", value: "open" },
        { label: "Rename", value: "rename" },
        { label: "Duplicate", value: "duplicate" },
        { label: "Archive", value: "archive", disabled: true },
        { separator: true as const },
        { label: "Delete", value: "delete", danger: true },
      ];
    </script>
    
    <ContextMenu {items}>
      <div
        class="flex h-36 items-center justify-center rounded-lg border border-dashed border-line text-sm text-muted"
      >
        Right-click here
      </div>
    </ContextMenu>
    ---
    import ContextMenu from "@/components/markas/ContextMenu.astro";
    
    const items = [
      { label: "Open", value: "open" },
      { label: "Rename", value: "rename" },
      { label: "Duplicate", value: "duplicate" },
      { label: "Archive", value: "archive", disabled: true },
      { separator: true as const },
      { label: "Delete", value: "delete", danger: true },
    ];
    ---
    
    <ContextMenu items={items}>
      <div
        class="flex h-36 items-center justify-center rounded-lg border border-dashed border-line text-sm text-muted"
      >
        Right-click here
      </div>
    </ContextMenu>
    import { Component } from "@angular/core";
    import { ContextMenu } from "./markas/context-menu.component";
    
    @Component({
      selector: "markas-example",
      imports: [ContextMenu],
      template: `
        <markas-context-menu [items]="items">
          <div [class]="area">Right-click here</div>
        </markas-context-menu>
      `,
    })
    export default class ContextMenuExample {
      protected readonly items = [
        { label: "Open", value: "open" },
        { label: "Rename", value: "rename" },
        { label: "Duplicate", value: "duplicate" },
        { label: "Archive", value: "archive", disabled: true },
        { separator: true as const },
        { label: "Delete", value: "delete", danger: true },
      ];
      protected readonly area =
        "flex h-36 items-center justify-center rounded-lg border border-dashed border-line text-sm text-muted";
    }

    Examples

    File item

    Quarterly report.pdf

    2.4 MB, edited yesterday

    Press Shift+F10 to open the context menu

    Quarterly report.pdf

    2.4 MB, edited yesterday

    Press Shift+F10 to open the context menu

    Quarterly report.pdf

    2.4 MB, edited yesterday

    Press Shift+F10 to open the context menu

    Quarterly report.pdf

    2.4 MB, edited yesterday

    Press Shift+F10 to open the context menu

    Quarterly report.pdf

    2.4 MB, edited yesterday

    Press Shift+F10 to open the context menu

    Disabled items

    Meeting notes

    Launch moves to Monday. Design review on Thursday, bring the updated mockups.

    Press Shift+F10 to open the context menu

    Meeting notes

    Launch moves to Monday. Design review on Thursday, bring the updated mockups.

    Press Shift+F10 to open the context menu

    Meeting notes

    Launch moves to Monday. Design review on Thursday, bring the updated mockups.

    Press Shift+F10 to open the context menu

    Meeting notes

    Launch moves to Monday. Design review on Thursday, bring the updated mockups.

    Press Shift+F10 to open the context menu

    Meeting notes

    Launch moves to Monday. Design review on Thursday, bring the updated mockups.

    Press Shift+F10 to open the context menu

    List rows

    • Website redesign In progress
      Press Shift+F10 to open the context menu
    • Mobile app Planned
      Press Shift+F10 to open the context menu
    • Website redesignIn progress
      Press Shift+F10 to open the context menu
    • Mobile appPlanned
      Press Shift+F10 to open the context menu
    • Website redesignIn progress
      Press Shift+F10 to open the context menu
    • Mobile appPlanned
      Press Shift+F10 to open the context menu
    • Website redesign In progress
      Press Shift+F10 to open the context menu
    • Mobile app Planned
      Press Shift+F10 to open the context menu
    • Website redesignIn progress
      Press Shift+F10 to open the context menu
    • Mobile appPlanned
      Press Shift+F10 to open the context menu

    Installation

    npx markasui@latest add context-menu

    Usage

    <x-markas.context-menu
        :items="[
            ['label' => 'Open', 'value' => 'open'],
            ['label' => 'Rename', 'value' => 'rename'],
            ['separator' => true],
            ['label' => 'Delete', 'value' => 'delete', 'danger' => true],
        ]"
        x-on:markas-select="console.log($event.detail)"
    >
        <div class="rounded-lg border border-dashed border-line p-8 text-sm text-muted">Right-click here</div>
    </x-markas.context-menu>

    Needs Alpine.js. Selecting an item dispatches a markas-select event with the item value in $event.detail. In Livewire: x-on:markas-select="$wire.handle($event.detail)".

    Livewire

    <x-markas.context-menu :items="$actions" wire:markas-select="run($event.detail)">
        ...
    </x-markas.context-menu>

    wire:markas-select calls a Livewire action with the picked value.

    import { ContextMenu } from "@/components/markas/ContextMenu";
    
    <ContextMenu
      items={[
        { label: "Open", value: "open" },
        { label: "Rename", value: "rename" },
        { separator: true },
        { label: "Delete", value: "delete", danger: true },
      ]}
      onSelect={(value) => console.log(value)}
    >
      <div className="rounded-lg border border-dashed border-line p-8 text-sm text-muted">
        Right-click here
      </div>
    </ContextMenu>;
    <template>
      <ContextMenu
        :items="[
          { label: 'Open', value: 'open' },
          { label: 'Rename', value: 'rename' },
          { separator: true },
          { label: 'Delete', value: 'delete', danger: true },
        ]"
        @select="(value) => console.log(value)"
      >
        <div
          class="rounded-lg border border-dashed border-line p-8 text-sm text-muted"
        >
          Right-click here
        </div>
      </ContextMenu>
    </template>
    <script lang="ts">
      import ContextMenu from "$lib/components/markas/ContextMenu.svelte";
    </script>
    
    <ContextMenu
      items={[
        { label: "Open", value: "open" },
        { label: "Rename", value: "rename" },
        { separator: true },
        { label: "Delete", value: "delete", danger: true },
      ]}
      onselect={(value) => console.log(value)}
    >
      <div
        class="rounded-lg border border-dashed border-line p-8 text-sm text-muted"
      >
        Right-click here
      </div>
    </ContextMenu>
    ---
    import ContextMenu from "@/components/markas/ContextMenu.astro";
    ---
    
    <ContextMenu
      items={[
        { label: "Open", value: "open" },
        { label: "Rename", value: "rename" },
        { separator: true },
        { label: "Delete", value: "delete", danger: true },
      ]}
    >
      <div class="rounded-lg border border-dashed border-line p-8 text-sm text-muted">
        Right-click here
      </div>
    </ContextMenu>
    
    <script>
      document.addEventListener("markas-select", (event) =>
        console.log((event as CustomEvent<string>).detail),
      );
    </script>

    A small bundled script runs every context menu on the page, also after view transitions. Selecting an item dispatches a bubbling markas-select event with the item value in detail.

    import { Component } from "@angular/core";
    import { ContextMenu } from "./markas/context-menu.component";
    
    @Component({
      selector: "app-file-card",
      imports: [ContextMenu],
      template: `
        <markas-context-menu [items]="items" (selected)="onSelect($event)">
          <div
            class="rounded-lg border border-dashed border-line p-8 text-sm text-muted"
          >
            Right-click here
          </div>
        </markas-context-menu>
      `,
    })
    export class FileCard {
      readonly items = [
        { label: "Open", value: "open" },
        { label: "Rename", value: "rename" },
        { separator: true as const },
        { label: "Delete", value: "delete", danger: true },
      ];
    
      onSelect(value: string) {}
    }
    • Attributes and class go to the trigger area, which is focusable. Shift+F10 or the ContextMenu key opens the menu from the keyboard.
    • When value is empty, the callback receives the item label.
    • The menu renders in the top layer through the Popover API and stays inside the viewport near the edges.
    • menuLabel and hintLabel default to English. Translate them for other languages.

    Props

    NameTypeDefaultDescription
    items{ label, value?, href?, danger?, disabled? }[] or { separator: true }[]Menu items. Items with href render as links, separators render as a dividing line.
    children / slotReactNode / slot / snippet-Content of the trigger area. Right-clicking anywhere in it opens the menu. Angular: the projected content.
    menuLabelstringContext menuAccessible name of the menu panel.
    hintLabelstringPress Shift+F10 to open the context menuScreen reader hint linked to the trigger area with aria-describedby.
    onSelect / @select / markas-select(value: string) => void-Called when an item is selected, with the item value (or label when value is empty). Blade dispatches a markas-select event.
    idstringautoMenu panel id. The hint uses this id with a -hint suffix.
    selectedoutput<string>-Angular only. Emits the item value (or label) when an item is selected. Svelte uses the onselect prop, Astro dispatches a markas-select event like Blade.

    Accessibility

    • The trigger area is focusable (tabindex=0) and described by a hidden hint that explains Shift+F10.
    • Right-click opens the menu at the pointer; Shift+F10 or the ContextMenu key opens it at the top left corner of the area. The first item receives focus.
    • Arrow Up and Arrow Down move between items (wrapping at the ends), Home and End jump to the first and last item, disabled items are skipped.
    • Escape closes the menu and returns focus to the area, Tab closes it. Clicking outside closes the menu (Popover API light dismiss).

    Related components

    More overlay components with the same classes in every framework.