carbon-react 119.6.0 → 119.6.1
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.
|
@@ -97,8 +97,8 @@ const FocusTrap = _ref => {
|
|
|
97
97
|
}, [trapWrappers]);
|
|
98
98
|
useEffect(() => {
|
|
99
99
|
const trapFn = ev => {
|
|
100
|
-
// block focus trap from working if it's not the topmost trap
|
|
101
|
-
if (!isTopModal) {
|
|
100
|
+
// block focus trap from working if it's not the topmost trap, or is currently closed
|
|
101
|
+
if (!isTopModal || !isOpen) {
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
104
|
const focusableElements = getFocusableElements(defaultFocusableSelectors);
|
|
@@ -108,7 +108,7 @@ const FocusTrap = _ref => {
|
|
|
108
108
|
return function cleanup() {
|
|
109
109
|
document.removeEventListener("keydown", trapFn, true);
|
|
110
110
|
};
|
|
111
|
-
}, [bespokeTrap, wrapperRef, focusableSelectors, getFocusableElements, isTopModal]);
|
|
111
|
+
}, [bespokeTrap, wrapperRef, focusableSelectors, getFocusableElements, isTopModal, isOpen]);
|
|
112
112
|
const updateCurrentFocusedElement = useCallback(() => {
|
|
113
113
|
const focusableElements = getFocusableElements(focusableSelectors || defaultFocusableSelectors);
|
|
114
114
|
const element = focusableElements?.find(el => el === document.activeElement);
|
|
@@ -163,13 +163,13 @@ const FocusTrap = _ref => {
|
|
|
163
163
|
});
|
|
164
164
|
return /*#__PURE__*/React.createElement("div", {
|
|
165
165
|
ref: trapRef
|
|
166
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
166
|
+
}, isOpen && /*#__PURE__*/React.createElement("div", {
|
|
167
167
|
"data-element": TAB_GUARD_TOP
|
|
168
168
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
169
169
|
,
|
|
170
170
|
tabIndex: 0,
|
|
171
171
|
onFocus: onTabGuardTopFocus(wrapperRef)
|
|
172
|
-
}), clonedChildren, /*#__PURE__*/React.createElement("div", {
|
|
172
|
+
}), clonedChildren, isOpen && /*#__PURE__*/React.createElement("div", {
|
|
173
173
|
"data-element": TAB_GUARD_BOTTOM
|
|
174
174
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
175
175
|
,
|
|
@@ -107,8 +107,8 @@ const FocusTrap = _ref => {
|
|
|
107
107
|
}, [trapWrappers]);
|
|
108
108
|
(0, _react.useEffect)(() => {
|
|
109
109
|
const trapFn = ev => {
|
|
110
|
-
// block focus trap from working if it's not the topmost trap
|
|
111
|
-
if (!isTopModal) {
|
|
110
|
+
// block focus trap from working if it's not the topmost trap, or is currently closed
|
|
111
|
+
if (!isTopModal || !isOpen) {
|
|
112
112
|
return;
|
|
113
113
|
}
|
|
114
114
|
const focusableElements = getFocusableElements(_focusTrapUtils.defaultFocusableSelectors);
|
|
@@ -118,7 +118,7 @@ const FocusTrap = _ref => {
|
|
|
118
118
|
return function cleanup() {
|
|
119
119
|
document.removeEventListener("keydown", trapFn, true);
|
|
120
120
|
};
|
|
121
|
-
}, [bespokeTrap, wrapperRef, focusableSelectors, getFocusableElements, isTopModal]);
|
|
121
|
+
}, [bespokeTrap, wrapperRef, focusableSelectors, getFocusableElements, isTopModal, isOpen]);
|
|
122
122
|
const updateCurrentFocusedElement = (0, _react.useCallback)(() => {
|
|
123
123
|
const focusableElements = getFocusableElements(focusableSelectors || _focusTrapUtils.defaultFocusableSelectors);
|
|
124
124
|
const element = focusableElements?.find(el => el === document.activeElement);
|
|
@@ -173,13 +173,13 @@ const FocusTrap = _ref => {
|
|
|
173
173
|
});
|
|
174
174
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
175
175
|
ref: trapRef
|
|
176
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
176
|
+
}, isOpen && /*#__PURE__*/_react.default.createElement("div", {
|
|
177
177
|
"data-element": TAB_GUARD_TOP
|
|
178
178
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
179
179
|
,
|
|
180
180
|
tabIndex: 0,
|
|
181
181
|
onFocus: onTabGuardTopFocus(wrapperRef)
|
|
182
|
-
}), clonedChildren, /*#__PURE__*/_react.default.createElement("div", {
|
|
182
|
+
}), clonedChildren, isOpen && /*#__PURE__*/_react.default.createElement("div", {
|
|
183
183
|
"data-element": TAB_GUARD_BOTTOM
|
|
184
184
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
185
185
|
,
|