Skip to content

Instantly share code, notes, and snippets.

@IlCallo
Created December 6, 2022 17:35
Show Gist options
  • Save IlCallo/07e64961118278fde36204512485cff2 to your computer and use it in GitHub Desktop.
Save IlCallo/07e64961118278fde36204512485cff2 to your computer and use it in GitHub Desktop.
import {
addEscapeKey,
removeEscapeKey,
} from 'quasar/src/utils/private/escape-key.js';
import { onMounted, onUnmounted } from 'vue';
// Quasar doesn't offer a way to hook into the esc handler from inside the dialog component itself,
// so we have to do it ourselves
// This requires the QDialog to have `no-esc-dismiss` and `no-shake` (purely aesthetic) prop enabled
export function useDialogEscapeKey(
handler: (event: Event) => void | Promise<void>,
) {
onMounted(() => {
addEscapeKey(handler);
});
onUnmounted(() => {
removeEscapeKey(handler);
});
}
declare module 'quasar/src/utils/private/escape-key.js' {
export function addEscapeKey(
handler: (event: Event) => void | Promise<void>,
): void;
export function removeEscapeKey(
handler: (event: Event) => void | Promise<void>,
): void;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment