Files
Montech_Landing/apps/landing/composables/useEscapeKey.ts
T
MahdiandCursor b0088c35d1 Replace the landing with the artifact design and rebuild the admin in Ant Design.
Adds consultation leads, section editors, and the one-time content reset for this release.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 20:36:06 +03:30

19 lines
552 B
TypeScript

import type { Ref } from "vue";
/** Calls `handler` on Escape while `active` is true. */
export function useEscapeKey(active: Ref<boolean>, handler: () => void) {
const onKey = (e: KeyboardEvent) => {
if (e.key === "Escape") handler();
};
watch(
active,
(on) => {
if (!import.meta.client) return;
if (on) document.addEventListener("keydown", onKey);
else document.removeEventListener("keydown", onKey);
},
{ immediate: true },
);
onBeforeUnmount(() => document.removeEventListener("keydown", onKey));
}