Skip to content

contextMenu

Decides what the context menu offers on a slot, a day or an event.

TypeMenuHook — (ctx: ContextMenuCtx, defaults: readonly ActionItem[]) => readonly ActionItem[] | null
Defaultthe built-in entries
Live update (update())Yes
Declared inpackages/dom/src/settings.ts

The calendar opens a menu on a right-click, a long press on a touch screen, or the Menu key / Shift+F10 on the focused slot or event. Its built-in entries depend on the target: “New event at 14:30”, “Go to this day” on time; “Open”, “Move…”, “Change duration…”, “Delete” on an event. An entry that does not apply is left out — “New event” without onCreateRequest, “Open” without onEventOpen, the editing entries without the right to edit; in a skipped hour “New event at…” carries a reason. With none of them, the browser’s own menu stays.

contextMenu(ctx, defaults) returns the entries to show: ctx holds the target (kind 'slot', 'day' or 'event', with its moment, date, resource or event instance) and the calendar’s state; defaults are the built-in entries (their ids: event.create, view.goToDay, event.open, event.move, event.resize, event.delete — on an occurrence its children event.delete.this, .following, .all). Keep them, reorder them, add your own — each { id, label, enabled, run?, command?, reason?, shortcut?, icon?, children? }; one enabled: false with a reason is shown greyed out with it — or return null (or []) to leave the browser’s own menu. The target is { kind: 'slot', date, instant, ambiguous, … }, { kind: 'day', date } or { kind: 'event', instance }, with resourceId in a resource view. The menu itself — keyboard, focus, sub-menus, placement, theme — is the calendar’s.

import { createCalendar } from '@dzcalendar/dom';
createCalendar(element, {
timeZone: 'Europe/Paris',
editable: true,
contextMenu: ({ target }, defaults) =>
target.kind === 'event'
? [...defaults, { id: 'invoice', label: 'Send the invoice', enabled: true, run: () => console.log('invoice', target.instance.event.id) }]
: defaults,
});

In Angular and Vue it goes in options; in React it is a prop.