WlMenu

Menu from a WlMenuItem list with groups and separators. Popup mode is controlled through toggle/show/hide.
Components / Actions v0.1.0

Change props to see the result: the example and code use the same settings. “Reset” restores the initial values.

Settings

ariaLabel

Accessible menu name.

Popup menu animation; defaults to WlConfig.motion (true).

Props items, popup, ariaLabelledby, pt, placement, align, models, handlers and slots can be edited in the SFC. See their descriptions in API.

Popup menu with a trigger button is shown in the example below.

Example

Choose an action · View: list · false

Focus: outside the example · pointer: outside the example

Explore the live example and copy its Vue SFC into your application. Settings on the left can be combined.

Code for your application

Vue SFC · current settings
<script setup lang="ts">
import { WlMenu, type WlMenuItem } from "legato-ui";
import { computed, ref } from "vue";
const selection = ref("Choose an action");
const compact = ref(false);
const view = ref("list");
const items = computed<WlMenuItem[]>(() => [
  { header: "Material" },
  { key: "edit", label: "Edit", icon: "edit", command: () => { selection.value = "Editing"; } },
  { key: "view", label: "View", items: [
    { key: "list", label: "List", type: "radio", group: "View", checked: view.value === "list", onCheckedChange: () => { view.value = "list"; } },
    { key: "grid", label: "Grid", type: "radio", group: "View", checked: view.value === "grid", onCheckedChange: () => { view.value = "grid"; } },
    { separator: true },
    { key: "compact", label: "Compact header", type: "checkbox", checked: compact.value, onCheckedChange: (checked) => { compact.value = checked; } }
  ] },
  { key: "lock", label: "Unavailable", disabled: true },
  { separator: true },
  { key: "delete", label: "Delete", icon: "trash", danger: true, command: () => { selection.value = "Deletion"; } }
]);
</script>

<template>
  <div class="wl-stack" data-space="md">
    <WlMenu :items="items" aria-label="Material actions"  />
    <p role="status" class="wl-text-small">{{ selection }} · {{ "View" }}: {{ view }} · {{ compact }}</p>
  </div>
</template>

Static and popup menus

Heading, separator, icons, shortcut label, disabled and danger; commands produce a local result.

No command selected yet.

↑/↓, Home and End move focus. Escape closes the popup. Shortcut displays the key combination; the application adds its handler.

Vue SFC · additional example
<script setup lang="ts">
import { WlButton, WlMenu, type WlMenuExpose, type WlMenuItem } from "legato-ui";
import { ref } from "vue";
const popup = ref<WlMenuExpose | null>(null);
const message = ref("No command selected yet.");
const items: WlMenuItem[] = [
  { header: "Material" },
  { key: "edit", label: "Edit", icon: "edit", shortcut: "Ctrl+E", command: () => message.value = "Editing opened." },
  { key: "copy", label: "Copy link", icon: "copy", command: () => message.value = "Local copy example." },
  { key: "export", label: "Export", icon: "download", disabled: true },
  { separator: true },
  { key: "remove", label: "Delete", icon: "trash", danger: true, command: () => message.value = "Deletion selected; the application adds confirmation." }
];
</script>

<template>
  <div class="wl-stack" data-space="lg">
    <div><WlMenu :items="items" aria-label="Static material commands" /></div>
    <div><WlButton @click="popup?.toggle($event)">{{ "Open popup menu" }}</WlButton><WlMenu
      ref="popup"
      popup
      :items="items"
      aria-label="Material popup commands"
    /></div>
    <p class="wl-text-small" role="status">{{ message }}</p>
    <p class="wl-text-small wl-text-muted">{{ "↑/↓, Home and End move focus. Escape closes the popup. Shortcut displays the key combination; the application adds its handler." }}</p>
  </div>
</template>