UNPKG

tdesign-react

Version:
42 lines (36 loc) 1.35 kB
/** * tdesign v1.15.1 * (c) 2025 tdesign * @license MIT */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var toConsumableArray = require('../_chunks/dep-e4e1901e.js'); var React = require('react'); require('../_chunks/dep-00b49251.js'); var dialogSet = /* @__PURE__ */new Set(); var useDialogEsc = function useDialogEsc(visible, dialog) { React.useEffect(function () { if (visible) { if (dialog !== null && dialog !== void 0 && dialog.current) { var _dialog$current; dialogSet.add(dialog); dialog === null || dialog === void 0 || (_dialog$current = dialog.current) === null || _dialog$current === void 0 || _dialog$current.focus(); } } else if (dialogSet.has(dialog)) { var _dialogList; dialogSet["delete"](dialog); var dialogList = toConsumableArray._toConsumableArray(dialogSet); (_dialogList = dialogList[dialogList.length - 1]) === null || _dialogList === void 0 || (_dialogList = _dialogList.current) === null || _dialogList === void 0 || _dialogList.focus(); } return function () { dialogSet.forEach(function (item) { if (item.current === null) { dialogSet["delete"](item); } }); }; }, [visible, dialog]); }; exports["default"] = useDialogEsc; //# sourceMappingURL=useDialogEsc.js.map