Skip to content
MarkasUI
Type to search

    Guide

    MarkasUI

    Form

    Feedback

    Overlay

    Navigation

    Data

    Sections

    Animations

    Backgrounds

    Buttons

    Templates

    Pages

    Dropdown Menu

    Action menu built on the Popover API, with keyboard navigation following the WAI-ARIA Menu Button pattern.

    <x-markas.dropdown-menu
        label="Actions"
        :items="[
            ['label' => 'Edit', 'value' => 'edit'],
            ['label' => 'Duplicate', 'value' => 'duplicate'],
            ['label' => 'Archive', 'value' => 'archive', 'disabled' => true],
            ['separator' => true],
            ['label' => 'Delete', 'value' => 'delete', 'danger' => true],
        ]"
    />
    import { DropdownMenu } from "@/components/markas/DropdownMenu";
    
    const items = [
      { label: "Edit", value: "edit" },
      { label: "Duplicate", value: "duplicate" },
      { label: "Archive", value: "archive", disabled: true },
      { separator: true as const },
      { label: "Delete", value: "delete", danger: true },
    ];
    
    export default function DropdownMenuExample() {
      return <DropdownMenu label="Actions" items={items} />;
    }
    <script setup lang="ts">
    import DropdownMenu from "@/components/markas/DropdownMenu.vue";
    
    const items = [
      { label: "Edit", value: "edit" },
      { label: "Duplicate", value: "duplicate" },
      { label: "Archive", value: "archive", disabled: true },
      { separator: true as const },
      { label: "Delete", value: "delete", danger: true },
    ];
    </script>
    
    <template>
      <DropdownMenu label="Actions" :items="items" />
    </template>
    <script lang="ts">
      import DropdownMenu from "$lib/components/markas/DropdownMenu.svelte";
    
      const items = [
        { label: "Edit", value: "edit" },
        { label: "Duplicate", value: "duplicate" },
        { label: "Archive", value: "archive", disabled: true },
        { separator: true as const },
        { label: "Delete", value: "delete", danger: true },
      ];
    </script>
    
    <DropdownMenu label="Actions" {items} />
    ---
    import DropdownMenu from "@/components/markas/DropdownMenu.astro";
    
    const items = [
      { label: "Edit", value: "edit" },
      { label: "Duplicate", value: "duplicate" },
      { label: "Archive", value: "archive", disabled: true },
      { separator: true as const },
      { label: "Delete", value: "delete", danger: true },
    ];
    ---
    
    <DropdownMenu label="Actions" items={items} />
    import { Component } from "@angular/core";
    import { DropdownMenu } from "./markas/dropdown-menu.component";
    
    @Component({
      selector: "markas-example",
      imports: [DropdownMenu],
      template: ` <markas-dropdown-menu label="Actions" [items]="items" /> `,
    })
    export default class DropdownMenuExample {
      protected readonly items = [
        { label: "Edit", value: "edit" },
        { label: "Duplicate", value: "duplicate" },
        { label: "Archive", value: "archive", disabled: true },
        { separator: true as const },
        { label: "Delete", value: "delete", danger: true },
      ];
    }

    Examples

    With links

    Destructive items

    Disabled items

    Icon trigger

    In a toolbar

    Installation

    npx markasui@latest add dropdown-menu

    Usage

    <x-markas.dropdown-menu
        label="Actions"
        :items="[
            ['label' => 'Edit', 'value' => 'edit'],
            ['label' => 'View details', 'href' => '/projects/1'],
            ['separator' => true],
            ['label' => 'Delete', 'value' => 'delete', 'danger' => true],
        ]"
        x-on:markas-select="console.log($event.detail)"
    />

    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.dropdown-menu label="Actions" :items="$actions" wire:markas-select="run($event.detail)" />

    Picking an item dispatches markas-select with the value; wire:markas-select calls a Livewire action with it. The open menu keeps its position across re-renders.

    import { DropdownMenu } from "@/components/markas/DropdownMenu";
    
    <DropdownMenu
      label="Actions"
      items={[
        { label: "Edit", value: "edit" },
        { label: "View details", href: "/projects/1" },
        { separator: true },
        { label: "Delete", value: "delete", danger: true },
      ]}
      onSelect={(value) => console.log(value)}
    />;
    <template>
      <DropdownMenu
        label="Actions"
        :items="[
          { label: 'Edit', value: 'edit' },
          { label: 'View details', href: '/projects/1' },
          { separator: true },
          { label: 'Delete', value: 'delete', danger: true },
        ]"
        @select="(value) => console.log(value)"
      />
    </template>
    <script lang="ts">
      import DropdownMenu from "$lib/components/markas/DropdownMenu.svelte";
    </script>
    
    <DropdownMenu
      label="Actions"
      items={[
        { label: "Edit", value: "edit" },
        { label: "View details", href: "/projects/1" },
        { separator: true },
        { label: "Delete", value: "delete", danger: true },
      ]}
      onselect={(value) => console.log(value)}
    />
    ---
    import DropdownMenu from "@/components/markas/DropdownMenu.astro";
    ---
    
    <DropdownMenu
      label="Actions"
      items={[
        { label: "Edit", value: "edit" },
        { label: "View details", href: "/projects/1" },
        { separator: true },
        { label: "Delete", value: "delete", danger: true },
      ]}
    />
    
    <script>
      document.addEventListener("markas-select", (event) =>
        console.log((event as CustomEvent<string>).detail),
      );
    </script>

    A small bundled script runs every dropdown 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 { DropdownMenu } from "./markas/dropdown-menu.component";
    
    @Component({
      selector: "app-project-actions",
      imports: [DropdownMenu],
      template: `
        <markas-dropdown-menu
          label="Actions"
          [items]="items"
          (selected)="onSelect($event)"
        />
      `,
    })
    export class ProjectActions {
      readonly items = [
        { label: "Edit", value: "edit" },
        { label: "View details", href: "/projects/1" },
        { separator: true as const },
        { label: "Delete", value: "delete", danger: true },
      ];
    
      onSelect(value: string) {}
    }

    The trigger content can be replaced with an element that has the trigger attribute (an ng-container works).

    • Replace the button content with the trigger slot (Blade and Vue) or the trigger prop (React). The chevron icon stays.
    • When value is empty, the callback receives the item label.
    • The menu panel renders in the top layer through the Popover API, so a parent with overflow: hidden never clips it.
    • The trigger text defaults to “Options”. Translate it with label.

    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.
    labelstringOptionsText of the trigger button.
    triggerslot / ReactNode / snippet-Custom trigger button content, replaces label. Angular: an element with the trigger attribute.
    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 trigger button uses this id with a -trigger 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 button uses aria-haspopup=menu, aria-expanded, and aria-controls pointing to the role=menu panel.
    • Enter, Space, or Arrow Down opens the menu and focuses the first item; Arrow Up focuses the last item.
    • 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 trigger. Clicking outside closes the menu (Popover API light dismiss).

    Related components

    More overlay components with the same classes in every framework.