From 53326100121eab968b69d6f60a27d6e42e1c9144 Mon Sep 17 00:00:00 2001 From: Sadegh Barati Date: Sat, 6 Jan 2024 11:10:26 +0330 Subject: [PATCH] docs: prevent default browser behaviour with `ctrl-k/j` in `useMagicKeys` (#246) build registry for stackblitz and codesandbox demos --- .../.vitepress/theme/layout/MainLayout.vue | 8 ++++++- .../default/example/CommandDialogDemo.vue | 21 ++++++++++++------- .../new-york/example/CommandDialogDemo.vue | 21 ++++++++++++------- .../registry/styles/default/dialog.json | 2 +- .../public/registry/styles/default/input.json | 2 +- .../registry/styles/new-york/dialog.json | 2 +- .../registry/styles/new-york/input.json | 2 +- 7 files changed, 37 insertions(+), 21 deletions(-) diff --git a/apps/www/.vitepress/theme/layout/MainLayout.vue b/apps/www/.vitepress/theme/layout/MainLayout.vue index 9a0b7a0c..23bc4121 100644 --- a/apps/www/.vitepress/theme/layout/MainLayout.vue +++ b/apps/www/.vitepress/theme/layout/MainLayout.vue @@ -49,7 +49,13 @@ const links = [ ] const isOpen = ref(false) -const { Meta_K, Ctrl_K } = useMagicKeys() +const { Meta_K, Ctrl_K } = useMagicKeys({ + passive: false, + onEventFired(e) { + if (e.key === 'k' && (e.metaKey || e.ctrlKey)) + e.preventDefault() + }, +}) watch([Meta_K, Ctrl_K], (v) => { if (v[0] || v[1]) diff --git a/apps/www/src/lib/registry/default/example/CommandDialogDemo.vue b/apps/www/src/lib/registry/default/example/CommandDialogDemo.vue index 9f18c79a..ddc3f24c 100644 --- a/apps/www/src/lib/registry/default/example/CommandDialogDemo.vue +++ b/apps/www/src/lib/registry/default/example/CommandDialogDemo.vue @@ -14,17 +14,22 @@ import { const open = ref(false) -const keys = useMagicKeys() -const CmdJ = keys['Cmd+J'] +const { Meta_J, Ctrl_J } = useMagicKeys({ + passive: false, + onEventFired(e) { + if (e.key === 'j' && (e.metaKey || e.ctrlKey)) + e.preventDefault() + }, +}) + +watch([Meta_J, Ctrl_J], (v) => { + if (v[0] || v[1]) + handleOpenChange() +}) function handleOpenChange() { open.value = !open.value } - -watch(CmdJ, (v) => { - if (v) - handleOpenChange() -})