UNPKG

element-plus

Version:
33 lines (32 loc) 1.03 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const vue_1 = require("vue"); const dom_1 = require("../../utils/dom"); const aria_1 = require("../../utils/aria"); const isServer_1 = __importDefault(require("../../utils/isServer")); const modalStack = []; const closeModal = (e) => { if (modalStack.length === 0) return; if (e.code === aria_1.EVENT_CODE.esc) { e.stopPropagation(); const topModal = modalStack[modalStack.length - 1]; topModal.handleClose(); } }; exports.default = (instance, visibleRef) => { vue_1.watch(() => visibleRef.value, val => { if (val) { modalStack.push(instance); } else { modalStack.splice(modalStack.findIndex(modal => modal === instance), 1); } }); }; if (!isServer_1.default) { dom_1.on(document, 'keydown', closeModal); }