Files
dsProject/dsBase/WebRoot/html/cdn/es/hooks/use-escape-keydown/index.mjs
2025-08-14 15:45:08 +08:00

22 lines
558 B
JavaScript

import { onMounted, onBeforeUnmount } from 'vue';
import { on, off } from '../../utils/dom.mjs';
import { EVENT_CODE } from '../../utils/aria.mjs';
const useEscapeKeydown = (handler) => {
const cachedHandler = (e) => {
const event = e;
if (event.key === EVENT_CODE.esc) {
handler == null ? void 0 : handler(event);
}
};
onMounted(() => {
on(document, "keydown", cachedHandler);
});
onBeforeUnmount(() => {
off(document, "keydown", cachedHandler);
});
};
export { useEscapeKeydown };
//# sourceMappingURL=index.mjs.map