UNPKG

tdesign-react

Version:
52 lines (46 loc) 1.38 kB
/** * tdesign v1.16.6 * (c) 2026 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var React = require('react'); var dialogStack = []; var useDialogEsc = function useDialogEsc(visible, dialog) { var addedToStackRef = React.useRef(false); var focusTopDialog = React.useCallback(function () { var lastDialog = dialogStack[dialogStack.length - 1]; if (lastDialog !== null && lastDialog !== void 0 && lastDialog.current) { lastDialog.current.focus(); } }, []); React.useEffect(function () { if (visible && dialog !== null && dialog !== void 0 && dialog.current && !addedToStackRef.current) { dialogStack.push(dialog); addedToStackRef.current = true; dialog.current.focus(); } }); React.useEffect(function () { if (!visible && addedToStackRef.current) { var index = dialogStack.indexOf(dialog); if (index > -1) { dialogStack.splice(index, 1); } addedToStackRef.current = false; } return function () { for (var i = dialogStack.length - 1; i >= 0; i--) { if (dialogStack[i].current === null) { dialogStack.splice(i, 1); } } }; }, [visible, dialog]); return { focusTopDialog: focusTopDialog }; }; exports["default"] = useDialogEsc; //# sourceMappingURL=useDialogEsc.js.map