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()
-})
@@ -37,7 +42,7 @@ watch(CmdJ, (v) => {
⌘J
-
+
No results found.
diff --git a/apps/www/src/lib/registry/new-york/example/CommandDialogDemo.vue b/apps/www/src/lib/registry/new-york/example/CommandDialogDemo.vue
index e8b4e11a..f5e1beb1 100644
--- a/apps/www/src/lib/registry/new-york/example/CommandDialogDemo.vue
+++ b/apps/www/src/lib/registry/new-york/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()
-})
@@ -37,7 +42,7 @@ watch(CmdJ, (v) => {
⌘J
-
+
No results found.
diff --git a/apps/www/src/public/registry/styles/default/dialog.json b/apps/www/src/public/registry/styles/default/dialog.json
index c9f9387f..76ff177f 100644
--- a/apps/www/src/public/registry/styles/default/dialog.json
+++ b/apps/www/src/public/registry/styles/default/dialog.json
@@ -7,7 +7,7 @@
"files": [
{
"name": "Dialog.vue",
- "content": "\n\n\n \n \n \n\n"
+ "content": "\n\n\n \n \n \n\n"
},
{
"name": "DialogClose.vue",
diff --git a/apps/www/src/public/registry/styles/default/input.json b/apps/www/src/public/registry/styles/default/input.json
index 4290905d..ae1e2ad9 100644
--- a/apps/www/src/public/registry/styles/default/input.json
+++ b/apps/www/src/public/registry/styles/default/input.json
@@ -9,7 +9,7 @@
"files": [
{
"name": "Input.vue",
- "content": "\n\n\n \n\n"
+ "content": "\n\n\n \n\n"
},
{
"name": "index.ts",
diff --git a/apps/www/src/public/registry/styles/new-york/dialog.json b/apps/www/src/public/registry/styles/new-york/dialog.json
index c7aade14..cb379fd1 100644
--- a/apps/www/src/public/registry/styles/new-york/dialog.json
+++ b/apps/www/src/public/registry/styles/new-york/dialog.json
@@ -7,7 +7,7 @@
"files": [
{
"name": "Dialog.vue",
- "content": "\n\n\n \n \n \n\n"
+ "content": "\n\n\n \n \n \n\n"
},
{
"name": "DialogClose.vue",
diff --git a/apps/www/src/public/registry/styles/new-york/input.json b/apps/www/src/public/registry/styles/new-york/input.json
index 26a6a806..fb565151 100644
--- a/apps/www/src/public/registry/styles/new-york/input.json
+++ b/apps/www/src/public/registry/styles/new-york/input.json
@@ -9,7 +9,7 @@
"files": [
{
"name": "Input.vue",
- "content": "\n\n\n \n\n"
+ "content": "\n\n\n \n\n"
},
{
"name": "index.ts",