fix: add isDialogOpen utility function and update keyboard shortcuts to respect dialog state
This commit is contained in:
parent
a45c150a3d
commit
f573db2fe0
@ -1,4 +1,5 @@
|
|||||||
import { onMounted, onBeforeUnmount, unref } from 'vue'
|
import { onMounted, onBeforeUnmount, unref } from 'vue'
|
||||||
|
import { isDialogOpen } from '@/utils/dialogs'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic global keyboard shortcuts composable.
|
* Generic global keyboard shortcuts composable.
|
||||||
@ -20,6 +21,7 @@ export function useKeyboardShortcuts(options) {
|
|||||||
shortcuts = [],
|
shortcuts = [],
|
||||||
ignoreTyping = true,
|
ignoreTyping = true,
|
||||||
target = typeof window !== 'undefined' ? window : null,
|
target = typeof window !== 'undefined' ? window : null,
|
||||||
|
skipWhenDialogOpen = true,
|
||||||
} = options || {}
|
} = options || {}
|
||||||
|
|
||||||
function isTypingEvent(e) {
|
function isTypingEvent(e) {
|
||||||
@ -49,6 +51,7 @@ export function useKeyboardShortcuts(options) {
|
|||||||
const isActive = typeof active === 'function' ? active() : unref(active)
|
const isActive = typeof active === 'function' ? active() : unref(active)
|
||||||
if (!isActive) return
|
if (!isActive) return
|
||||||
if (isTypingEvent(e)) return
|
if (isTypingEvent(e)) return
|
||||||
|
if (skipWhenDialogOpen && isDialogOpen()) return
|
||||||
|
|
||||||
for (const def of shortcuts) {
|
for (const def of shortcuts) {
|
||||||
if (!def) continue
|
if (!def) continue
|
||||||
|
|||||||
@ -3,6 +3,10 @@ import { reactive, ref } from 'vue'
|
|||||||
|
|
||||||
let dialogs = ref([])
|
let dialogs = ref([])
|
||||||
|
|
||||||
|
export function isDialogOpen() {
|
||||||
|
return dialogs.value.some((d) => d.show)
|
||||||
|
}
|
||||||
|
|
||||||
export let Dialogs = {
|
export let Dialogs = {
|
||||||
name: 'Dialogs',
|
name: 'Dialogs',
|
||||||
render() {
|
render() {
|
||||||
@ -18,9 +22,7 @@ export let Dialogs = {
|
|||||||
dialog.message && (
|
dialog.message && (
|
||||||
<p class="text-p-base text-ink-gray-7">{dialog.message}</p>
|
<p class="text-p-base text-ink-gray-7">{dialog.message}</p>
|
||||||
),
|
),
|
||||||
dialog.html && (
|
dialog.html && <div v-html={dialog.html} />,
|
||||||
<div v-html={dialog.html} />
|
|
||||||
),
|
|
||||||
<ErrorMessage class="mt-2" message={dialog.error} />,
|
<ErrorMessage class="mt-2" message={dialog.error} />,
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user