linear-react-components-ui 1.1.22-beta.1 → 1.1.22-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dialog/base/index.js +26 -12
- package/package.json +1 -1
package/lib/dialog/base/index.js
CHANGED
|
@@ -35,10 +35,11 @@ const BaseDialog = props => {
|
|
|
35
35
|
const {
|
|
36
36
|
headerRef
|
|
37
37
|
} = (0, _react.useContext)(_form.FormDialogContext);
|
|
38
|
-
const wrapperEl = (0, _react.useRef)(null);
|
|
39
|
-
const modalContainerRef = (0, _react.useRef)(null);
|
|
40
38
|
const [isDragging, setIsDragging] = (0, _react.useState)(false);
|
|
41
39
|
const [open = true, setOpen] = (0, _react.useState)(openProp);
|
|
40
|
+
const wrapperEl = (0, _react.useRef)(null);
|
|
41
|
+
const modalContainerRef = (0, _react.useRef)(null);
|
|
42
|
+
const focusableElementsRef = (0, _react.useRef)([]);
|
|
42
43
|
if (openProp !== undefined && openProp !== open) {
|
|
43
44
|
setOpen(openProp);
|
|
44
45
|
}
|
|
@@ -64,17 +65,12 @@ const BaseDialog = props => {
|
|
|
64
65
|
handleClose();
|
|
65
66
|
}
|
|
66
67
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (focusOnAnotherField && elementsFocusable?.length) {
|
|
72
|
-
const firstElement = elementsFocusable[0];
|
|
73
|
-
setTimeout(() => {
|
|
74
|
-
firstElement.focus();
|
|
75
|
-
}, 150);
|
|
68
|
+
(0, _react.useEffect)(() => {
|
|
69
|
+
if (open && modalContainerRef.current) {
|
|
70
|
+
focusableElementsRef.current = Array.from(modalContainerRef.current.querySelectorAll("button, a, input, select, textarea, [tabindex]:not([tabindex='-1'])"));
|
|
71
|
+
focusableElementsRef.current[0]?.focus();
|
|
76
72
|
}
|
|
77
|
-
};
|
|
73
|
+
}, [open]);
|
|
78
74
|
const onDialogPositionChange = _ref => {
|
|
79
75
|
let {
|
|
80
76
|
positionX,
|
|
@@ -116,8 +112,26 @@ const BaseDialog = props => {
|
|
|
116
112
|
const onMouseUp = () => {
|
|
117
113
|
if (wrapperEl.current) setIsDragging(false);
|
|
118
114
|
};
|
|
115
|
+
const handleKeyDown = e => {
|
|
116
|
+
if (e.key === 'Tab') {
|
|
117
|
+
const {
|
|
118
|
+
current: elements
|
|
119
|
+
} = focusableElementsRef;
|
|
120
|
+
if (elements.length === 0) return;
|
|
121
|
+
const firstElement = elements[0];
|
|
122
|
+
const lastElement = elements[elements.length - 1];
|
|
123
|
+
if (e.shiftKey && document.activeElement === firstElement) {
|
|
124
|
+
lastElement.focus();
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
} else if (!e.shiftKey && document.activeElement === lastElement) {
|
|
127
|
+
firstElement.focus();
|
|
128
|
+
e.preventDefault();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
119
132
|
const createdModal = /*#__PURE__*/_react.default.createElement("div", {
|
|
120
133
|
id: id,
|
|
134
|
+
onKeyDown: handleKeyDown,
|
|
121
135
|
ref: modalContainerRef,
|
|
122
136
|
className: "modalcontainer",
|
|
123
137
|
onMouseDown: handleClickOutside,
|