Keyboard Shortcuts Plugin

The Keyboard Shortcuts plugin enables global keyboard controls for navigation, event management, and clipboard operations.

Installation

Install the plugin package:

npm install @dayflow/plugin-keyboard-shortcuts
pnpm add @dayflow/plugin-keyboard-shortcuts
yarn add @dayflow/plugin-keyboard-shortcuts
bun add @dayflow/plugin-keyboard-shortcuts

Usage

import { useCalendarApp, DayFlowCalendar } from '@dayflow/react';
import { createKeyboardShortcutsPlugin } from '@dayflow/plugin-keyboard-shortcuts';

function MyCalendar() {
  const calendar = useCalendarApp({
    views: [
      /* your views */
    ],
    plugins: [
      createKeyboardShortcutsPlugin({
        // Optional configuration
      }),
    ],
  });

  return <DayFlowCalendar calendar={calendar} />;
}
<template>
  <DayFlowCalendar :calendar="calendar" />
</template>

<script setup>
import { DayFlowCalendar, useCalendarApp } from '@dayflow/vue';
import { createKeyboardShortcutsPlugin } from '@dayflow/plugin-keyboard-shortcuts';

const calendar = useCalendarApp({
  views: [
    /* your views */
  ],
  plugins: [
    createKeyboardShortcutsPlugin({
      // Optional configuration
    }),
  ],
});
</script>
import { Component } from '@angular/core';
import { DayFlowCalendarModule } from '@dayflow/angular';
import { createKeyboardShortcutsPlugin } from '@dayflow/plugin-keyboard-shortcuts';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [DayFlowCalendarModule],
  template: `<dayflow-calendar [calendar]="calendar"></dayflow-calendar>`
})
export class AppComponent {
  calendar = {
    views: [
      /* your views */
    ],
    plugins: [
      createKeyboardShortcutsPlugin({
        // Optional configuration
      })
    ]
  };
}
<script>
  import { DayFlowCalendar, useCalendarApp } from '@dayflow/svelte';
  import { createKeyboardShortcutsPlugin } from '@dayflow/plugin-keyboard-shortcuts';

  const calendar = useCalendarApp({
    views: [
      /* your views */
    ],
    plugins: [
      createKeyboardShortcutsPlugin({
        // Optional configuration
      }),
    ],
  });
</script>

<DayFlowCalendar {calendar} />

Default Shortcuts

ActionKey (Mac)Key (Windows/Linux)
Go to TodayCmd + TCtrl + T
SearchCmd + FCtrl + F
New EventCmd + NCtrl + N
NavigationArrowLeft / ArrowRightArrowLeft / ArrowRight
Tab Through EventsTab / Shift + TabTab / Shift + Tab
UndoCmd + ZCtrl + Z
RedoCmd + Shift + Z / Cmd + YCtrl + Y
Copy EventCmd + CCtrl + C
Cut EventCmd + XCtrl + X
Paste EventCmd + VCtrl + V
Delete EventBackspace / DeleteBackspace / Delete
Close Dialogs/PanelsEscEsc

Configuration

You can customize the key mappings and provide custom callbacks for each action:

createKeyboardShortcutsPlugin({
  keyMap: {
    today: 't',
    search: 'f',
    prev: 'ArrowLeft',
    next: 'ArrowRight',
    undo: 'z',
    redo: 'y',
    delete: 'Delete',
    newEvent: 'n',
  },
  callbacks: {
    undo: app => {
      console.log('Custom undo logic');
      app.undo();
    },
    redo: app => {
      console.log('Custom redo logic');
      if (app.redo) app.redo();
    },
    delete: app => {
      if (confirm('Are you sure?')) {
        const selectedId = app.state.selectedEventId;
        if (selectedId) app.deleteEvent(selectedId);
      }
    },
  },
});

Available Callbacks

The following callbacks are supported in the callbacks object:

  • undo, redo, paste (receives app)
  • copy, cut, delete (receives app and event?: Event)
  • today, search, prev, next, newEvent, dismiss (receives app)
  • tab (receives app and reverse: boolean)

Plugin API

Access the plugin handle to control shortcut handling at runtime:

import { type KeyboardShortcutsService } from '@dayflow/plugin-keyboard-shortcuts';

const kb = app.getPlugin<KeyboardShortcutsService>('keyboard-shortcuts');

KeyboardShortcutsService

MethodReturnsDescription
enable()voidRe-enables shortcut handling
disable()voidSuppresses all shortcuts until enable() is called
isEnabled()booleanReturns whether shortcuts are currently active

A common use case is suppressing calendar shortcuts while a custom modal or rich text editor is open:

function MyModal() {
  const kb = app.getPlugin<KeyboardShortcutsService>('keyboard-shortcuts');

  useEffect(() => {
    kb?.disable();
    return () => kb?.enable(); // restore on unmount
  }, []);

  // ...
}

You can also programmatically dismiss any open UI:

app.dismissUI();

On this page