Lewati ke konten
MarkasUI
Ketik untuk mencari

    Panduan

    MarkasUI

    Form

    Feedback

    Overlay

    Navigasi

    Data

    Section

    Animasi

    Latar

    Tombol

    Template

    Halaman

    Context Menu

    Menu yang terbuka saat area diklik kanan atau Shift+F10 ditekan, tampil di posisi kursor lewat Popover API dengan keyboard sesuai WAI-ARIA 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
    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";
    }

    Contoh

    Item file

    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

    Item nonaktif

    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

    Baris daftar

    • 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

    Instalasi

    npx markasui@latest add context-menu

    Pemakaian

    <x-markas.context-menu
        menu-label="Menu konteks"
        hint-label="Tekan Shift+F10 untuk membuka menu konteks"
        :items="[
            ['label' => 'Buka', 'value' => 'buka'],
            ['label' => 'Ganti nama', 'value' => 'ganti-nama'],
            ['separator' => true],
            ['label' => 'Hapus', 'value' => 'hapus', '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">Klik kanan di sini</div>
    </x-markas.context-menu>

    Butuh Alpine.js. Item yang dipilih memancarkan event markas-select dengan $event.detail berisi value item. Di Livewire: x-on:markas-select="$wire.aksi($event.detail)".

    Livewire

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

    wire:markas-select memanggil action Livewire dengan value yang dipilih.

    import { ContextMenu } from "@/components/markas/ContextMenu";
    
    <ContextMenu
      menuLabel="Menu konteks"
      hintLabel="Tekan Shift+F10 untuk membuka menu konteks"
      items={[
        { label: "Buka", value: "buka" },
        { label: "Ganti nama", value: "ganti-nama" },
        { separator: true },
        { label: "Hapus", value: "hapus", danger: true },
      ]}
      onSelect={(value) => console.log(value)}
    >
      <div className="rounded-lg border border-dashed border-line p-8 text-sm text-muted">
        Klik kanan di sini
      </div>
    </ContextMenu>;
    <template>
      <ContextMenu
        menu-label="Menu konteks"
        hint-label="Tekan Shift+F10 untuk membuka menu konteks"
        :items="[
          { label: 'Buka', value: 'buka' },
          { label: 'Ganti nama', value: 'ganti-nama' },
          { separator: true },
          { label: 'Hapus', value: 'hapus', danger: true },
        ]"
        @select="(value) => console.log(value)"
      >
        <div
          class="rounded-lg border border-dashed border-line p-8 text-sm text-muted"
        >
          Klik kanan di sini
        </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"
      >
        Klik kanan di sini
      </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">
        Klik kanan di sini
      </div>
    </ContextMenu>
    
    <script>
      document.addEventListener("markas-select", (event) =>
        console.log((event as CustomEvent<string>).detail),
      );
    </script>

    Satu script kecil yang dibundel menjalankan semua context menu di halaman, juga setelah view transition. Memilih item memancarkan event markas-select (bubble) dengan value item di 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"
          >
            Klik kanan di sini
          </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) {}
    }
    • Atribut dan class jatuh ke area pemicu yang bisa difokus. Shift+F10 atau tombol ContextMenu membuka menu dari keyboard.
    • Kalau value kosong, callback menerima label item.
    • Menu tampil di top layer lewat Popover API dan tetap di dalam layar saat dekat tepi.
    • menuLabel dan hintLabel default berbahasa Inggris. Isi dengan teks Indonesia seperti contoh di atas.

    Props

    NamaTipeDefaultKeterangan
    items{ label, value?, href?, danger?, disabled? }[] or { separator: true }[]Daftar item menu. Item dengan href dirender sebagai link, separator menjadi garis pemisah.
    children / slotReactNode / slot / snippet-Isi area pemicu. Klik kanan di mana saja di dalamnya membuka menu. Angular: konten yang diproyeksikan.
    menuLabelstringContext menuNama aksesibel panel menu. Default "Context menu", isi misalnya "Menu konteks".
    hintLabelstringPress Shift+F10 to open the context menuPetunjuk pembaca layar yang ditautkan ke area lewat aria-describedby. Isi misalnya "Tekan Shift+F10 untuk membuka menu konteks".
    onSelect / @select / markas-select(value: string) => void-Dipanggil saat item dipilih dengan value item (atau label bila value kosong). Blade memancarkan event markas-select.
    idstringautoId panel menu. Petunjuk memakai id ini dengan akhiran -hint.
    selectedoutput<string>-Khusus Angular. Dipancarkan dengan value item (atau label) saat item dipilih. Svelte memakai prop onselect, Astro memancarkan event markas-select seperti Blade.

    Aksesibilitas

    • Area pemicu bisa difokus (tabindex=0) dan dideskripsikan oleh petunjuk tersembunyi tentang Shift+F10.
    • Klik kanan membuka menu di posisi kursor; Shift+F10 atau tombol ContextMenu membukanya di sudut kiri atas area. Item pertama menerima fokus.
    • Panah atas dan bawah berpindah item (berputar di ujung), Home dan End ke item pertama dan terakhir, item nonaktif dilewati.
    • Escape menutup menu dan mengembalikan fokus ke area, Tab menutupnya. Klik di luar menutup menu (light dismiss Popover API).

    Komponen terkait

    Komponen overlay lain dengan class yang sama di setiap framework.