Keyboard Shortcuts

This plugin binds a global keydown listener and maps it to scheduler actions. Bindings are ignored while the user is typing in an input, textarea, select, or contenteditable element.

Installation

npm install @dayflow-scheduler/plugin-keyboard-shortcuts

Usage

The factory takes a required config object: pass {} to accept every default.

import { useSchedulerApp, DayflowScheduler } from '@dayflow-scheduler/react';
import { createSchedulerKeyboardShortcutsPlugin } from '@dayflow-scheduler/plugin-keyboard-shortcuts';

export function MyScheduler() {
  const app = useSchedulerApp({
    resources,
    events,
    plugins: [createSchedulerKeyboardShortcutsPlugin({})],
  });

  return <DayflowScheduler app={app} />;
}
import { useSchedulerApp } from '@dayflow-scheduler/vue';
import { createSchedulerKeyboardShortcutsPlugin } from '@dayflow-scheduler/plugin-keyboard-shortcuts';

const app = useSchedulerApp({
  resources,
  events,
  plugins: [createSchedulerKeyboardShortcutsPlugin({})],
});
import { SchedulerApp } from '@dayflow-scheduler/angular';
import { createSchedulerKeyboardShortcutsPlugin } from '@dayflow-scheduler/plugin-keyboard-shortcuts';

app = new SchedulerApp({
  resources: this.resources,
  events: this.events,
  plugins: [createSchedulerKeyboardShortcutsPlugin({})],
});
import { createSchedulerApp } from '@dayflow-scheduler/svelte';
import { createSchedulerKeyboardShortcutsPlugin } from '@dayflow-scheduler/plugin-keyboard-shortcuts';

const app = createSchedulerApp({
  resources,
  events,
  plugins: [createSchedulerKeyboardShortcutsPlugin({})],
});

Default Shortcuts

ActionmacOSWindows / Linux
Go to todayCmd + TCtrl + T
SearchCmd + FCtrl + F
New eventCmd + NCtrl + N
Previous / next range / /
Cycle through eventsTab / Shift + TabTab / Shift + Tab
UndoCmd + ZCtrl + Z
RedoCmd + Shift + Z / Cmd + YCtrl + Y
Copy / cut / paste eventCmd + C / X / VCtrl + C / X / V
Delete eventBackspace / DeleteBackspace / Delete
Close dialogs and panelsEscEsc

Options

OptionTypeDefaultDescription
enabledbooleantrueSet to false to detach the listener without removing the plugin.
keyMapKeyMap-Overrides the default key bindings.
callbacksCallbacks-Overrides the default action handlers.

KeyMap

Each entry is a KeyboardEvent.key value. Actions that need Cmd/Ctrl list only the letter: the modifier is always required. Navigation keys match without a modifier.

KeyDefaultTriggered byAction
today't'Cmd/Ctrl + TJump to today.
search'f'Cmd/Ctrl + FOpen the search bar.
newEvent'n'Cmd/Ctrl + NStart new event creation.
prev'ArrowLeft'Navigate to the previous range.
next'ArrowRight'Navigate to the next range.
undo'z'Cmd/Ctrl + ZUndo the last change.
redo'y'Cmd/Ctrl + Y or Cmd + Shift + ZRedo the last undone change.
copy'c'Cmd/Ctrl + CCopy the selected event.
cut'x'Cmd/Ctrl + XCut the selected event.
paste'v'Cmd/Ctrl + VPaste the copied event.
delete'Delete'Backspace or DeleteDelete the selected event.
createSchedulerKeyboardShortcutsPlugin({
  keyMap: { today: 'd', newEvent: 'i' },
});

Only list the keys you want to change; unlisted keys keep their defaults.

Callbacks

Callbacks replace the default action. Each receives the live app instance and may return a promise. Two signatures exist:

  • AppOnlyCallback: (app: ISchedulerApp) => void | Promise<void>
  • SelectedEventCallback: (app: ISchedulerApp, event?: SchedulerEvent) => void | Promise<void>
CallbackSignatureDefault behavior
todayAppOnlyCallbackCalls app.goToToday().
prevAppOnlyCallbackCalls app.goToPrevious().
nextAppOnlyCallbackCalls app.goToNext().
searchAppOnlyCallbackOpens the search bar and focuses the input.
dismissAppOnlyCallbackCalls app.dismissUI().
pasteAppOnlyCallbackPastes the clipboard event at the selected event's position.
copySelectedEventCallbackCopies the selected event to the internal clipboard.
cutSelectedEventCallbackCopies, then deletes the selected event.
deleteSelectedEventCallbackCalls app.deleteEvent(event.id).
tab(app: ISchedulerApp, reverse: boolean) => void | Promise<void>Cycles focus through visible events. reverse is true for Shift + Tab.
newEventAppOnlyCallbackNo default: provide one to handle event creation.
undoAppOnlyCallbackNo default: provide one to hook into your undo stack.
redoAppOnlyCallbackNo default: provide one to hook into your redo stack.
createSchedulerKeyboardShortcutsPlugin({
  callbacks: {
    newEvent: app => openMyCreateDialog(app.getCurrentDate()),
    undo: app => app.undo(),
    delete: (app, event) => {
      if (event && confirm(`Delete "${event.title}"?`)) {
        app.deleteEvent(event.id);
      }
    },
  },
});

The app argument is the same instance returned by useSchedulerApp; see The App Instance for its full API.

Dismissing UI Programmatically

Esc maps to app.dismissUI(), which you can also call directly to close any open panel, dialog, or menu:

app.dismissUI();

On this page