carbon-react 144.12.0 → 144.12.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.
- package/esm/__internal__/focus-trap/focus-trap.component.js +1 -1
- package/esm/components/popover-container/popover-container.component.js +34 -1
- package/lib/__internal__/focus-trap/focus-trap.component.js +1 -1
- package/lib/components/popover-container/popover-container.component.js +34 -1
- package/package.json +1 -1
|
@@ -156,7 +156,7 @@ const FocusTrap = ({
|
|
|
156
156
|
onFocus: updateCurrentFocusedElement
|
|
157
157
|
});
|
|
158
158
|
|
|
159
|
-
// passes focusProps, sets tabIndex and onBlur if no tabIndex has been
|
|
159
|
+
// passes focusProps, sets tabIndex and onBlur if no tabIndex has been explicitly set on child
|
|
160
160
|
const clonedChildren = React.Children.map(children, child => {
|
|
161
161
|
const focusableChild = child;
|
|
162
162
|
return /*#__PURE__*/React.cloneElement(focusableChild, focusProps(focusableChild?.props?.tabIndex === undefined));
|
|
@@ -15,6 +15,7 @@ import FocusTrap from "../../__internal__/focus-trap";
|
|
|
15
15
|
import ModalContext from "../modal/__internal__/modal.context";
|
|
16
16
|
import useFocusPortalContent from "../../hooks/__internal__/useFocusPortalContent";
|
|
17
17
|
import tagComponent from "../../__internal__/utils/helpers/tags/tags";
|
|
18
|
+
import { defaultFocusableSelectors } from "../../__internal__/focus-trap/focus-trap-utils";
|
|
18
19
|
export const renderOpen = ({
|
|
19
20
|
tabIndex,
|
|
20
21
|
onClick,
|
|
@@ -127,6 +128,24 @@ export const PopoverContainer = ({
|
|
|
127
128
|
closePopover(e);
|
|
128
129
|
};
|
|
129
130
|
useFocusPortalContent(shouldCoverButton ? undefined : popoverContentNodeRef, shouldCoverButton ? undefined : openButtonRef, closePopover);
|
|
131
|
+
const onFocusNextElement = useCallback(ev => {
|
|
132
|
+
const allFocusableElements = Array.from(document.querySelectorAll(defaultFocusableSelectors) || /* istanbul ignore next */[]);
|
|
133
|
+
const filteredElements = allFocusableElements.filter(el => el === openButtonRef.current || Number(el.tabIndex) !== -1);
|
|
134
|
+
const openButtonRefIndex = filteredElements.indexOf(openButtonRef.current);
|
|
135
|
+
filteredElements[openButtonRefIndex + 1].focus();
|
|
136
|
+
closePopover(ev);
|
|
137
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
138
|
+
}, []);
|
|
139
|
+
const handleFocusGuard = (direction, ev) => {
|
|
140
|
+
if (direction === "next" && onFocusNextElement) {
|
|
141
|
+
// Focus the next focusable element outside of the popover
|
|
142
|
+
onFocusNextElement(ev);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// istanbul ignore else
|
|
147
|
+
if (direction === "prev") openButtonRef.current?.focus();
|
|
148
|
+
};
|
|
130
149
|
const renderOpenComponentProps = {
|
|
131
150
|
tabIndex: 0,
|
|
132
151
|
"aria-expanded": isOpen,
|
|
@@ -173,7 +192,21 @@ export const PopoverContainer = ({
|
|
|
173
192
|
}, /*#__PURE__*/React.createElement(FocusTrap, {
|
|
174
193
|
wrapperRef: popoverContentNodeRef,
|
|
175
194
|
isOpen: isOpen
|
|
176
|
-
}, popover())) :
|
|
195
|
+
}, popover())) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
196
|
+
"data-element": "tab-guard-top"
|
|
197
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
198
|
+
,
|
|
199
|
+
tabIndex: 0,
|
|
200
|
+
"aria-hidden": true,
|
|
201
|
+
onFocus: ev => handleFocusGuard("prev", ev)
|
|
202
|
+
}), popover(), /*#__PURE__*/React.createElement("div", {
|
|
203
|
+
"data-element": "tab-guard-bottom"
|
|
204
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
205
|
+
,
|
|
206
|
+
tabIndex: 0,
|
|
207
|
+
"aria-hidden": true,
|
|
208
|
+
onFocus: ev => handleFocusGuard("next", ev)
|
|
209
|
+
}));
|
|
177
210
|
return /*#__PURE__*/React.createElement(PopoverContainerWrapperStyle, {
|
|
178
211
|
"data-component": "popover-container",
|
|
179
212
|
onMouseDown: handleClick
|
|
@@ -165,7 +165,7 @@ const FocusTrap = ({
|
|
|
165
165
|
onFocus: updateCurrentFocusedElement
|
|
166
166
|
});
|
|
167
167
|
|
|
168
|
-
// passes focusProps, sets tabIndex and onBlur if no tabIndex has been
|
|
168
|
+
// passes focusProps, sets tabIndex and onBlur if no tabIndex has been explicitly set on child
|
|
169
169
|
const clonedChildren = _react.default.Children.map(children, child => {
|
|
170
170
|
const focusableChild = child;
|
|
171
171
|
return /*#__PURE__*/_react.default.cloneElement(focusableChild, focusProps(focusableChild?.props?.tabIndex === undefined));
|
|
@@ -20,6 +20,7 @@ var _focusTrap = _interopRequireDefault(require("../../__internal__/focus-trap")
|
|
|
20
20
|
var _modal = _interopRequireDefault(require("../modal/__internal__/modal.context"));
|
|
21
21
|
var _useFocusPortalContent = _interopRequireDefault(require("../../hooks/__internal__/useFocusPortalContent"));
|
|
22
22
|
var _tags = _interopRequireDefault(require("../../__internal__/utils/helpers/tags/tags"));
|
|
23
|
+
var _focusTrapUtils = require("../../__internal__/focus-trap/focus-trap-utils");
|
|
23
24
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
24
25
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
25
26
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -138,6 +139,24 @@ const PopoverContainer = ({
|
|
|
138
139
|
closePopover(e);
|
|
139
140
|
};
|
|
140
141
|
(0, _useFocusPortalContent.default)(shouldCoverButton ? undefined : popoverContentNodeRef, shouldCoverButton ? undefined : openButtonRef, closePopover);
|
|
142
|
+
const onFocusNextElement = (0, _react.useCallback)(ev => {
|
|
143
|
+
const allFocusableElements = Array.from(document.querySelectorAll(_focusTrapUtils.defaultFocusableSelectors) || /* istanbul ignore next */[]);
|
|
144
|
+
const filteredElements = allFocusableElements.filter(el => el === openButtonRef.current || Number(el.tabIndex) !== -1);
|
|
145
|
+
const openButtonRefIndex = filteredElements.indexOf(openButtonRef.current);
|
|
146
|
+
filteredElements[openButtonRefIndex + 1].focus();
|
|
147
|
+
closePopover(ev);
|
|
148
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
149
|
+
}, []);
|
|
150
|
+
const handleFocusGuard = (direction, ev) => {
|
|
151
|
+
if (direction === "next" && onFocusNextElement) {
|
|
152
|
+
// Focus the next focusable element outside of the popover
|
|
153
|
+
onFocusNextElement(ev);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// istanbul ignore else
|
|
158
|
+
if (direction === "prev") openButtonRef.current?.focus();
|
|
159
|
+
};
|
|
141
160
|
const renderOpenComponentProps = {
|
|
142
161
|
tabIndex: 0,
|
|
143
162
|
"aria-expanded": isOpen,
|
|
@@ -184,7 +203,21 @@ const PopoverContainer = ({
|
|
|
184
203
|
}, /*#__PURE__*/_react.default.createElement(_focusTrap.default, {
|
|
185
204
|
wrapperRef: popoverContentNodeRef,
|
|
186
205
|
isOpen: isOpen
|
|
187
|
-
}, popover())) :
|
|
206
|
+
}, popover())) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
|
|
207
|
+
"data-element": "tab-guard-top"
|
|
208
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
209
|
+
,
|
|
210
|
+
tabIndex: 0,
|
|
211
|
+
"aria-hidden": true,
|
|
212
|
+
onFocus: ev => handleFocusGuard("prev", ev)
|
|
213
|
+
}), popover(), /*#__PURE__*/_react.default.createElement("div", {
|
|
214
|
+
"data-element": "tab-guard-bottom"
|
|
215
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
216
|
+
,
|
|
217
|
+
tabIndex: 0,
|
|
218
|
+
"aria-hidden": true,
|
|
219
|
+
onFocus: ev => handleFocusGuard("next", ev)
|
|
220
|
+
}));
|
|
188
221
|
return /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerWrapperStyle, {
|
|
189
222
|
"data-component": "popover-container",
|
|
190
223
|
onMouseDown: handleClick
|