orcs-design-system 3.1.30 → 3.1.32
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/es/components/Modal/index.js +14 -56
- package/package.json +2 -1
|
@@ -2,14 +2,14 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
4
|
var _excluded = ["children", "width", "height", "maxWidth", "maxHeight", "minWidth", "minHeight", "overflow", "onClose", "theme", "visible", "overlayID", "modalID", "headerContent", "footerContent"];
|
|
5
|
-
import React, { useCallback, useEffect, useMemo,
|
|
5
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
6
6
|
import ReactDOM from "react-dom";
|
|
7
7
|
import useOnclickOutside from "react-cool-onclickoutside";
|
|
8
8
|
import PropTypes from "prop-types";
|
|
9
9
|
import styled, { keyframes, ThemeProvider } from "styled-components";
|
|
10
|
+
import FocusTrap from "focus-trap-react";
|
|
10
11
|
import { css } from "@styled-system/css";
|
|
11
12
|
import { themeGet } from "@styled-system/theme-get";
|
|
12
|
-
import { commonKeys } from "../../hooks/keypress";
|
|
13
13
|
import Icon from "../Icon";
|
|
14
14
|
import Button from "../Button";
|
|
15
15
|
import Flex from "../Flex";
|
|
@@ -74,18 +74,6 @@ var ScrollableContent = styled.div.withConfig({
|
|
|
74
74
|
var isHidden = function isHidden(el) {
|
|
75
75
|
return window.getComputedStyle(el).display === "none";
|
|
76
76
|
};
|
|
77
|
-
var makeRootNotFocusable = function makeRootNotFocusable() {
|
|
78
|
-
var root = document.getElementById("root");
|
|
79
|
-
root === null || root === void 0 || root.setAttribute("aria-hidden", true);
|
|
80
|
-
root === null || root === void 0 || root.setAttribute("inert", true);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
// Make root focusable again
|
|
84
|
-
var makeRootFocusable = function makeRootFocusable() {
|
|
85
|
-
var root = document.getElementById("root");
|
|
86
|
-
root === null || root === void 0 || root.removeAttribute("aria-hidden");
|
|
87
|
-
root === null || root === void 0 || root.removeAttribute("inert");
|
|
88
|
-
};
|
|
89
77
|
var Modal = function Modal(_ref) {
|
|
90
78
|
var children = _ref.children,
|
|
91
79
|
width = _ref.width,
|
|
@@ -120,23 +108,6 @@ var Modal = function Modal(_ref) {
|
|
|
120
108
|
return headerContent;
|
|
121
109
|
}
|
|
122
110
|
}, [restProps.ariaLabel, headerContent]);
|
|
123
|
-
|
|
124
|
-
// Initial focus point for keyboard navigation
|
|
125
|
-
var modalContainerRef = useRef();
|
|
126
|
-
|
|
127
|
-
// If bottom becomes focused then re-focus the close button
|
|
128
|
-
|
|
129
|
-
// Ref to close button
|
|
130
|
-
var button = useRef();
|
|
131
|
-
var setFocus = useCallback(function () {
|
|
132
|
-
var autoFocusable = modalContainerRef.current.querySelector("*[autofocus='true']");
|
|
133
|
-
var firstInput = modalContainerRef.current.querySelectorAll("input")[0];
|
|
134
|
-
if (autoFocusable) {
|
|
135
|
-
autoFocusable.focus();
|
|
136
|
-
} else {
|
|
137
|
-
firstInput === null || firstInput === void 0 || firstInput.focus();
|
|
138
|
-
}
|
|
139
|
-
}, [modalContainerRef]);
|
|
140
111
|
var focusLastActiveElement = useCallback(function () {
|
|
141
112
|
if (!lastActiveElement) return;
|
|
142
113
|
if (lastActiveElement !== null && lastActiveElement !== void 0 && lastActiveElement.dataset.actionMenuId && isHidden(lastActiveElement === null || lastActiveElement === void 0 ? void 0 : lastActiveElement.parentNode)) {
|
|
@@ -149,35 +120,25 @@ var Modal = function Modal(_ref) {
|
|
|
149
120
|
|
|
150
121
|
// On becoming visible focus the top
|
|
151
122
|
useEffect(function () {
|
|
152
|
-
if (visible) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
setLastActiveElement(document.activeElement);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// Prevents tabbing of elements underneath modal overlay
|
|
159
|
-
makeRootNotFocusable();
|
|
160
|
-
|
|
161
|
-
// See function
|
|
162
|
-
setFocus();
|
|
123
|
+
if (visible && !lastActiveElement) {
|
|
124
|
+
// Keep track of last clicked element to refocus to after dialog closes
|
|
125
|
+
setLastActiveElement(document.activeElement);
|
|
163
126
|
} else if (!visible) {
|
|
164
|
-
makeRootFocusable();
|
|
165
127
|
setLastActiveElement(null);
|
|
128
|
+
|
|
166
129
|
// Focus the last active element before modal open when modal is closed
|
|
167
130
|
focusLastActiveElement();
|
|
168
131
|
}
|
|
169
|
-
}, [visible,
|
|
132
|
+
}, [visible, focusLastActiveElement, lastActiveElement]);
|
|
170
133
|
var component = /*#__PURE__*/React.createElement(Overlay, _extends({
|
|
171
134
|
alignItems: "center",
|
|
172
135
|
justifyContent: "center",
|
|
173
|
-
onKeyUp: function onKeyUp(e) {
|
|
174
|
-
e.stopPropagation();
|
|
175
|
-
if ([commonKeys.ESCAPE, commonKeys.ESC].includes(e.key)) {
|
|
176
|
-
onClose();
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
136
|
id: overlayID
|
|
180
|
-
}, restProps), /*#__PURE__*/React.createElement(
|
|
137
|
+
}, restProps), visible && /*#__PURE__*/React.createElement(FocusTrap, {
|
|
138
|
+
focusTrapOptions: {
|
|
139
|
+
onDeactivate: onClose
|
|
140
|
+
}
|
|
141
|
+
}, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
|
|
181
142
|
ref: modalRef,
|
|
182
143
|
role: "dialog",
|
|
183
144
|
"aria-modal": "true",
|
|
@@ -193,13 +154,11 @@ var Modal = function Modal(_ref) {
|
|
|
193
154
|
borderRadius: "2",
|
|
194
155
|
bg: "white",
|
|
195
156
|
p: "r",
|
|
196
|
-
id: modalID
|
|
197
|
-
ref: modalContainerRef
|
|
157
|
+
id: modalID
|
|
198
158
|
}, headerContent ? /*#__PURE__*/React.createElement(HeaderContent, null, /*#__PURE__*/React.createElement(Box, {
|
|
199
159
|
mr: "xl",
|
|
200
160
|
width: "100%"
|
|
201
161
|
}, headerContent), /*#__PURE__*/React.createElement(CloseButton, {
|
|
202
|
-
ref: button,
|
|
203
162
|
onClick: onClose,
|
|
204
163
|
className: "modal-close",
|
|
205
164
|
small: true,
|
|
@@ -210,7 +169,6 @@ var Modal = function Modal(_ref) {
|
|
|
210
169
|
color: "greyDark",
|
|
211
170
|
size: "lg"
|
|
212
171
|
}))) : /*#__PURE__*/React.createElement(CloseButton, {
|
|
213
|
-
ref: button,
|
|
214
172
|
onClick: onClose,
|
|
215
173
|
className: "modal-close",
|
|
216
174
|
small: true,
|
|
@@ -223,7 +181,7 @@ var Modal = function Modal(_ref) {
|
|
|
223
181
|
})), /*#__PURE__*/React.createElement(ScrollableContent, {
|
|
224
182
|
headerContent: headerContent,
|
|
225
183
|
overflow: overflow
|
|
226
|
-
}, children), footerContent && /*#__PURE__*/React.createElement(FooterContent, null, footerContent))));
|
|
184
|
+
}, children), footerContent && /*#__PURE__*/React.createElement(FooterContent, null, footerContent))))));
|
|
227
185
|
var wrapper = visible && /*#__PURE__*/ReactDOM.createPortal(theme ? /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
228
186
|
theme: theme
|
|
229
187
|
}, component) : component, document.body);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orcs-design-system",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.32",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": "18.17.1"
|
|
6
6
|
},
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@styled-system/prop-types": "^5.1.5",
|
|
48
48
|
"@styled-system/should-forward-prop": "^5.1.5",
|
|
49
49
|
"@styled-system/theme-get": "^5.1.2",
|
|
50
|
+
"focus-trap-react": "^10.2.3",
|
|
50
51
|
"moment": "^2.29.4",
|
|
51
52
|
"polished": "^3.7.1",
|
|
52
53
|
"prop-types": "^15.6.2",
|