1 |
|
2 | "use strict";
|
3 | var __importStar = (this && this.__importStar) || function (mod) {
|
4 | if (mod && mod.__esModule) return mod;
|
5 | var result = {};
|
6 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
7 | result["default"] = mod;
|
8 | return result;
|
9 | };
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 | var react_1 = __importStar(require("react"));
|
12 | var ag_grid_community_1 = require("ag-grid-community");
|
13 | var beansContext_1 = require("./beansContext");
|
14 | var TabGuardCompRef = function (props, forwardRef) {
|
15 | var children = props.children, eFocusableElement = props.eFocusableElement, onTabKeyDown = props.onTabKeyDown, gridCtrl = props.gridCtrl;
|
16 | var context = react_1.useContext(beansContext_1.BeansContext).context;
|
17 | var topTabGuardRef = react_1.useRef(null);
|
18 | var bottomTabGuardRef = react_1.useRef(null);
|
19 | var tabGuardCtrlRef = react_1.useRef();
|
20 | var _a = react_1.useState(), tabIndex = _a[0], setTabIndex = _a[1];
|
21 | react_1.useImperativeHandle(forwardRef, function () { return ({
|
22 | forceFocusOutOfContainer: function () {
|
23 | tabGuardCtrlRef.current.forceFocusOutOfContainer();
|
24 | }
|
25 | }); });
|
26 | react_1.useEffect(function () {
|
27 | var eTopGuard = topTabGuardRef.current;
|
28 | var eBottomGuard = bottomTabGuardRef.current;
|
29 | var compProxy = {
|
30 | setTabIndex: function (value) { return value == null ? setTabIndex(undefined) : setTabIndex(parseInt(value, 10)); }
|
31 | };
|
32 | var ctrl = tabGuardCtrlRef.current = context.createBean(new ag_grid_community_1.TabGuardCtrl({
|
33 | comp: compProxy,
|
34 | eTopGuard: eTopGuard,
|
35 | eBottomGuard: eBottomGuard,
|
36 | eFocusableElement: eFocusableElement,
|
37 | onTabKeyDown: onTabKeyDown,
|
38 | focusInnerElement: function (fromBottom) { return gridCtrl.focusInnerElement(fromBottom); }
|
39 | }));
|
40 | return function () {
|
41 | context.destroyBean(ctrl);
|
42 | };
|
43 | }, []);
|
44 | var createTabGuard = function (side) { return (react_1.default.createElement("div", { className: "ag-tab-guard ag-tab-guard-" + side, role: "presentation", tabIndex: tabIndex, ref: side === 'top' ? topTabGuardRef : bottomTabGuardRef })); };
|
45 | return (react_1.default.createElement(react_1.default.Fragment, null,
|
46 | createTabGuard('top'),
|
47 | children,
|
48 | createTabGuard('bottom')));
|
49 | };
|
50 | var TabGuardComp = react_1.forwardRef(TabGuardCompRef);
|
51 | exports.default = react_1.memo(TabGuardComp);
|