1 | import { __rest } from "tslib";
|
2 | import * as React from 'react';
|
3 | import styles from '@patternfly/react-styles/css/components/DualListSelector/dual-list-selector';
|
4 | import { css } from '@patternfly/react-styles';
|
5 | import { handleArrows } from '../../helpers';
|
6 | export const DualListSelectorControlsWrapperBase = (_a) => {
|
7 | var { innerRef, children = null, className, 'aria-label': ariaLabel = 'Controls for moving options between lists' } = _a, props = __rest(_a, ["innerRef", "children", "className", 'aria-label']);
|
8 | const wrapperRef = innerRef || React.useRef(null);
|
9 |
|
10 |
|
11 | const handleKeys = (event) => {
|
12 | if (!wrapperRef.current ||
|
13 | (wrapperRef.current !== event.target.closest('.pf-c-dual-list-selector__controls') &&
|
14 | !Array.from(wrapperRef.current.getElementsByClassName('pf-c-dual-list-selector__controls')).includes(event.target.closest('.pf-c-dual-list-selector__controls')))) {
|
15 | return;
|
16 | }
|
17 | event.stopImmediatePropagation();
|
18 | const controls = Array.from(wrapperRef.current.getElementsByTagName('BUTTON')).filter(el => !el.classList.contains('pf-m-disabled'));
|
19 | const activeElement = document.activeElement;
|
20 | handleArrows(event, controls, (element) => activeElement.contains(element), (element) => element, undefined, undefined, true, false);
|
21 | };
|
22 | React.useEffect(() => {
|
23 | window.addEventListener('keydown', handleKeys);
|
24 | return () => {
|
25 | window.removeEventListener('keydown', handleKeys);
|
26 | };
|
27 | }, [wrapperRef.current]);
|
28 | return (React.createElement("div", Object.assign({ className: css(styles.dualListSelectorControls, className), tabIndex: 0, ref: wrapperRef, "aria-label": ariaLabel }, props), children));
|
29 | };
|
30 | DualListSelectorControlsWrapperBase.displayName = 'DualListSelectorControlsWrapperBase';
|
31 | export const DualListSelectorControlsWrapper = React.forwardRef((props, ref) => (React.createElement(DualListSelectorControlsWrapperBase, Object.assign({ innerRef: ref }, props))));
|
32 | DualListSelectorControlsWrapper.displayName = 'DualListSelectorControlsWrapper';
|
33 |
|
\ | No newline at end of file |