UNPKG

2.74 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.DualListSelectorControlsWrapper = exports.DualListSelectorControlsWrapperBase = void 0;
4const tslib_1 = require("tslib");
5const React = tslib_1.__importStar(require("react"));
6const dual_list_selector_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/DualListSelector/dual-list-selector"));
7const react_styles_1 = require("@patternfly/react-styles");
8const helpers_1 = require("../../helpers");
9const DualListSelectorControlsWrapperBase = (_a) => {
10 var { innerRef, children = null, className, 'aria-label': ariaLabel = 'Controls for moving options between lists' } = _a, props = tslib_1.__rest(_a, ["innerRef", "children", "className", 'aria-label']);
11 const wrapperRef = innerRef || React.useRef(null);
12 // Adds keyboard navigation to the dynamically built dual list selector controls. Works when controls are dynamically built
13 // as well as when they are passed in via children.
14 const handleKeys = (event) => {
15 if (!wrapperRef.current ||
16 (wrapperRef.current !== event.target.closest('.pf-c-dual-list-selector__controls') &&
17 !Array.from(wrapperRef.current.getElementsByClassName('pf-c-dual-list-selector__controls')).includes(event.target.closest('.pf-c-dual-list-selector__controls')))) {
18 return;
19 }
20 event.stopImmediatePropagation();
21 const controls = Array.from(wrapperRef.current.getElementsByTagName('BUTTON')).filter(el => !el.classList.contains('pf-m-disabled'));
22 const activeElement = document.activeElement;
23 helpers_1.handleArrows(event, controls, (element) => activeElement.contains(element), (element) => element, undefined, undefined, true, false);
24 };
25 React.useEffect(() => {
26 window.addEventListener('keydown', handleKeys);
27 return () => {
28 window.removeEventListener('keydown', handleKeys);
29 };
30 }, [wrapperRef.current]);
31 return (React.createElement("div", Object.assign({ className: react_styles_1.css(dual_list_selector_1.default.dualListSelectorControls, className), tabIndex: 0, ref: wrapperRef, "aria-label": ariaLabel }, props), children));
32};
33exports.DualListSelectorControlsWrapperBase = DualListSelectorControlsWrapperBase;
34exports.DualListSelectorControlsWrapperBase.displayName = 'DualListSelectorControlsWrapperBase';
35exports.DualListSelectorControlsWrapper = React.forwardRef((props, ref) => (React.createElement(exports.DualListSelectorControlsWrapperBase, Object.assign({ innerRef: ref }, props))));
36exports.DualListSelectorControlsWrapper.displayName = 'DualListSelectorControlsWrapper';
37//# sourceMappingURL=DualListSelectorControlsWrapper.js.map
\No newline at end of file