carbon-react 109.2.4 → 109.3.2
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__/field-help/field-help.component.d.ts +10 -0
- package/esm/__internal__/field-help/field-help.component.js +12 -16
- package/esm/__internal__/field-help/field-help.style.d.ts +8 -0
- package/esm/__internal__/field-help/field-help.style.js +2 -10
- package/esm/__internal__/field-help/index.d.ts +2 -1
- package/esm/__internal__/focus-trap/focus-trap-utils.d.ts +1 -2
- package/esm/__internal__/focus-trap/focus-trap-utils.js +57 -8
- package/esm/__internal__/focus-trap/focus-trap.component.js +35 -25
- package/esm/__spec_helper__/index.d.ts +1 -0
- package/esm/__spec_helper__/index.js +4 -10
- package/esm/__spec_helper__/mock-match-media.d.ts +2 -2
- package/esm/__spec_helper__/mock-match-media.js +2 -2
- package/esm/__spec_helper__/mock-resize-observer.d.ts +2 -0
- package/esm/components/alert/alert.component.js +9 -0
- package/esm/components/dialog/dialog.component.js +9 -2
- package/esm/components/dialog/dialog.d.ts +2 -0
- package/esm/components/dialog-full-screen/dialog-full-screen.component.js +9 -2
- package/esm/components/dialog-full-screen/dialog-full-screen.d.ts +2 -0
- package/esm/components/grid/grid-container/grid-container.component.d.ts +8 -0
- package/esm/components/grid/grid-container/grid-container.component.js +1821 -21
- package/esm/components/grid/grid-container/grid-container.style.d.ts +3 -0
- package/esm/components/grid/grid-container/grid-container.style.js +2 -2
- package/esm/components/grid/grid-container/index.d.ts +2 -1
- package/esm/components/grid/grid-item/grid-item.component.d.ts +11 -0
- package/esm/components/grid/grid-item/grid-item.component.js +1221 -45
- package/esm/components/grid/grid-item/grid-item.style.d.ts +17 -0
- package/esm/components/grid/grid-item/grid-item.style.js +38 -62
- package/esm/components/grid/grid-item/index.d.ts +2 -1
- package/esm/components/grid/index.d.ts +2 -0
- package/esm/components/grid/index.js +2 -3
- package/esm/components/multi-action-button/multi-action-button.component.js +14 -84
- package/esm/components/select/utils/highlight-part-of-text.js +13 -1
- package/esm/components/select/utils/with-filter.hoc.js +3 -2
- package/esm/components/sidebar/sidebar.component.js +9 -2
- package/esm/components/sidebar/sidebar.d.ts +2 -0
- package/esm/components/split-button/split-button.component.js +15 -82
- package/esm/components/toast/toast.component.js +35 -9
- package/esm/components/toast/toast.d.ts +5 -1
- package/esm/hooks/__internal__/useMenuKeyboardNavigation/index.d.ts +1 -0
- package/esm/hooks/__internal__/useMenuKeyboardNavigation/index.js +1 -0
- package/esm/hooks/__internal__/useMenuKeyboardNavigation/useMenuKeyboardNavigation.d.ts +2 -0
- package/esm/hooks/__internal__/useMenuKeyboardNavigation/useMenuKeyboardNavigation.js +70 -0
- package/lib/__internal__/field-help/field-help.component.d.ts +10 -0
- package/lib/__internal__/field-help/field-help.component.js +12 -16
- package/lib/__internal__/field-help/field-help.style.d.ts +8 -0
- package/lib/__internal__/field-help/field-help.style.js +2 -13
- package/lib/__internal__/field-help/index.d.ts +2 -1
- package/lib/__internal__/focus-trap/focus-trap-utils.d.ts +1 -2
- package/lib/__internal__/focus-trap/focus-trap-utils.js +57 -10
- package/lib/__internal__/focus-trap/focus-trap.component.js +34 -24
- package/lib/__spec_helper__/index.d.ts +1 -0
- package/lib/__spec_helper__/index.js +3 -10
- package/lib/__spec_helper__/mock-match-media.d.ts +2 -2
- package/lib/__spec_helper__/mock-match-media.js +4 -4
- package/lib/__spec_helper__/mock-resize-observer.d.ts +2 -0
- package/lib/components/alert/alert.component.js +9 -0
- package/lib/components/dialog/dialog.component.js +9 -2
- package/lib/components/dialog/dialog.d.ts +2 -0
- package/lib/components/dialog-full-screen/dialog-full-screen.component.js +9 -2
- package/lib/components/dialog-full-screen/dialog-full-screen.d.ts +2 -0
- package/lib/components/grid/grid-container/grid-container.component.d.ts +8 -0
- package/lib/components/grid/grid-container/grid-container.component.js +1826 -22
- package/lib/components/grid/grid-container/grid-container.style.d.ts +3 -0
- package/lib/components/grid/grid-container/grid-container.style.js +2 -2
- package/lib/components/grid/grid-container/index.d.ts +2 -1
- package/lib/components/grid/grid-item/grid-item.component.d.ts +11 -0
- package/lib/components/grid/grid-item/grid-item.component.js +1221 -46
- package/lib/components/grid/grid-item/grid-item.style.d.ts +17 -0
- package/lib/components/grid/grid-item/grid-item.style.js +37 -67
- package/lib/components/grid/grid-item/index.d.ts +2 -1
- package/lib/components/grid/index.d.ts +2 -0
- package/lib/components/multi-action-button/multi-action-button.component.js +13 -83
- package/lib/components/select/utils/highlight-part-of-text.js +13 -1
- package/lib/components/select/utils/with-filter.hoc.js +3 -2
- package/lib/components/sidebar/sidebar.component.js +9 -2
- package/lib/components/sidebar/sidebar.d.ts +2 -0
- package/lib/components/split-button/split-button.component.js +14 -83
- package/lib/components/toast/toast.component.js +35 -7
- package/lib/components/toast/toast.d.ts +5 -1
- package/lib/hooks/__internal__/useMenuKeyboardNavigation/index.d.ts +1 -0
- package/lib/hooks/__internal__/useMenuKeyboardNavigation/index.js +15 -0
- package/lib/hooks/__internal__/useMenuKeyboardNavigation/package.json +6 -0
- package/lib/hooks/__internal__/useMenuKeyboardNavigation/useMenuKeyboardNavigation.d.ts +2 -0
- package/lib/hooks/__internal__/useMenuKeyboardNavigation/useMenuKeyboardNavigation.js +85 -0
- package/package.json +3 -4
- package/esm/__internal__/field-help/field-help.d.ts +0 -14
- package/esm/components/grid/grid-container/grid-container.d.ts +0 -18
- package/esm/components/grid/grid-item/grid-item.d.ts +0 -42
- package/lib/__internal__/field-help/field-help.d.ts +0 -14
- package/lib/components/grid/grid-container/grid-container.d.ts +0 -18
- package/lib/components/grid/grid-item/grid-item.d.ts +0 -42
|
@@ -25,8 +25,12 @@ export interface ToastPropTypes {
|
|
|
25
25
|
targetPortalId?: string;
|
|
26
26
|
/** Maximum toast width */
|
|
27
27
|
maxWidth?: string;
|
|
28
|
+
/** Disables auto focus functionality when the Toast has a close icon */
|
|
29
|
+
disableAutoFocus?: boolean;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
declare
|
|
32
|
+
declare function Toast(
|
|
33
|
+
props: ToastPropTypes & React.RefAttributes<HTMLDivElement>
|
|
34
|
+
): JSX.Element;
|
|
31
35
|
|
|
32
36
|
export default Toast;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./useMenuKeyboardNavigation";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./useMenuKeyboardNavigation";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useCallback, useMemo } from "react";
|
|
2
|
+
import Events from "../../../__internal__/utils/helpers/events";
|
|
3
|
+
import { defaultFocusableSelectors } from "../../../__internal__/focus-trap/focus-trap-utils";
|
|
4
|
+
export default ((mainControlRef, childrenRefs, hide) => {
|
|
5
|
+
const childrenLength = useMemo(() => childrenRefs.length, [childrenRefs]);
|
|
6
|
+
const handleKeyDown = useCallback(ev => {
|
|
7
|
+
ev.preventDefault();
|
|
8
|
+
const currentIndex = childrenRefs === null || childrenRefs === void 0 ? void 0 : childrenRefs.findIndex(node => node.current === document.activeElement);
|
|
9
|
+
let nextIndex = -1;
|
|
10
|
+
|
|
11
|
+
const refocusMainControl = () => {
|
|
12
|
+
var _mainControlRef$curre;
|
|
13
|
+
|
|
14
|
+
hide();
|
|
15
|
+
(_mainControlRef$curre = mainControlRef.current) === null || _mainControlRef$curre === void 0 ? void 0 : _mainControlRef$curre.focus();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const arrowModifierPressed = ev.ctrlKey || ev.metaKey;
|
|
19
|
+
|
|
20
|
+
if (Events.isEndKey(ev) || arrowModifierPressed && Events.isDownKey(ev)) {
|
|
21
|
+
nextIndex = childrenLength - 1;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (Events.isHomeKey(ev) || arrowModifierPressed && Events.isUpKey(ev)) {
|
|
25
|
+
nextIndex = 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!arrowModifierPressed && Events.isUpKey(ev) && currentIndex > 0) {
|
|
29
|
+
nextIndex = currentIndex - 1;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!arrowModifierPressed && Events.isDownKey(ev) && currentIndex < childrenLength - 1) {
|
|
33
|
+
nextIndex = currentIndex + 1;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const tabPressed = Events.isTabKey(ev);
|
|
37
|
+
const tabShiftPressed = tabPressed && Events.isShiftKey(ev);
|
|
38
|
+
|
|
39
|
+
if (tabShiftPressed) {
|
|
40
|
+
if (currentIndex === 0) {
|
|
41
|
+
refocusMainControl();
|
|
42
|
+
} else {
|
|
43
|
+
nextIndex = currentIndex - 1;
|
|
44
|
+
}
|
|
45
|
+
} else if (tabPressed) {
|
|
46
|
+
if (currentIndex === childrenLength - 1) {
|
|
47
|
+
var _elements;
|
|
48
|
+
|
|
49
|
+
const elements = Array.from(document.querySelectorAll(defaultFocusableSelectors)).filter(el => Number(el.tabIndex) !== -1);
|
|
50
|
+
const indexOf = elements.indexOf(mainControlRef.current);
|
|
51
|
+
(_elements = elements[indexOf + 1]) === null || _elements === void 0 ? void 0 : _elements.focus(); // // timeout enforces that the "hide" method will be run after browser focuses on the next element
|
|
52
|
+
|
|
53
|
+
setTimeout(hide, 0);
|
|
54
|
+
} else {
|
|
55
|
+
nextIndex = currentIndex + 1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (nextIndex > -1) {
|
|
60
|
+
var _childrenRefs$nextInd;
|
|
61
|
+
|
|
62
|
+
(_childrenRefs$nextInd = childrenRefs[nextIndex].current) === null || _childrenRefs$nextInd === void 0 ? void 0 : _childrenRefs$nextInd.focus();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (Events.isEscKey(ev)) {
|
|
66
|
+
refocusMainControl();
|
|
67
|
+
}
|
|
68
|
+
}, [childrenLength, hide, childrenRefs, mainControlRef]);
|
|
69
|
+
return handleKeyDown;
|
|
70
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { StyledFieldHelpProps } from "./field-help.style";
|
|
3
|
+
export interface FieldHelpProps extends StyledFieldHelpProps {
|
|
4
|
+
/** Child elements */
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
/** The unique id of the FieldHelp component */
|
|
7
|
+
id?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const FieldHelp: ({ children, labelInline, labelWidth, id, }: FieldHelpProps) => JSX.Element;
|
|
10
|
+
export default FieldHelp;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.FieldHelp = void 0;
|
|
7
7
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
|
|
@@ -13,28 +13,24 @@ var _fieldHelp = _interopRequireDefault(require("./field-help.style"));
|
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
|
|
16
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
17
|
-
|
|
18
16
|
const FieldHelp = ({
|
|
19
17
|
children,
|
|
20
18
|
labelInline,
|
|
21
|
-
labelWidth,
|
|
22
|
-
|
|
23
|
-
}) => /*#__PURE__*/_react.default.createElement(_fieldHelp.default,
|
|
19
|
+
labelWidth = 30,
|
|
20
|
+
id
|
|
21
|
+
}) => /*#__PURE__*/_react.default.createElement(_fieldHelp.default, {
|
|
24
22
|
"data-element": "help",
|
|
25
23
|
labelInline: labelInline,
|
|
26
|
-
labelWidth: labelWidth
|
|
27
|
-
|
|
24
|
+
labelWidth: labelWidth,
|
|
25
|
+
id: id
|
|
26
|
+
}, children);
|
|
28
27
|
|
|
28
|
+
exports.FieldHelp = FieldHelp;
|
|
29
29
|
FieldHelp.propTypes = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
labelInline: _propTypes.default.bool,
|
|
35
|
-
|
|
36
|
-
/** Width of a label in percentage. Works only when labelInline is true */
|
|
37
|
-
labelWidth: _propTypes.default.number
|
|
30
|
+
"children": _propTypes.default.node,
|
|
31
|
+
"id": _propTypes.default.string,
|
|
32
|
+
"labelInline": _propTypes.default.bool,
|
|
33
|
+
"labelWidth": _propTypes.default.number
|
|
38
34
|
};
|
|
39
35
|
var _default = FieldHelp;
|
|
40
36
|
exports.default = _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface StyledFieldHelpProps {
|
|
2
|
+
/** When true, label is placed in line an input */
|
|
3
|
+
labelInline?: boolean;
|
|
4
|
+
/** Width of a label in percentage. Works only when labelInline is true */
|
|
5
|
+
labelWidth?: number;
|
|
6
|
+
}
|
|
7
|
+
declare const StyledFieldHelp: import("styled-components").StyledComponent<"span", any, StyledFieldHelpProps, never>;
|
|
8
|
+
export default StyledFieldHelp;
|
|
@@ -7,15 +7,11 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
9
9
|
|
|
10
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
15
11
|
|
|
16
12
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
13
|
|
|
18
|
-
const
|
|
14
|
+
const StyledFieldHelp = _styledComponents.default.span`
|
|
19
15
|
display: block;
|
|
20
16
|
flex: 1;
|
|
21
17
|
margin-top: 8px;
|
|
@@ -29,12 +25,5 @@ const FieldHelpStyle = _styledComponents.default.span`
|
|
|
29
25
|
padding-left: 0;
|
|
30
26
|
`}
|
|
31
27
|
`;
|
|
32
|
-
|
|
33
|
-
labelWidth: 30
|
|
34
|
-
};
|
|
35
|
-
FieldHelpStyle.propTypes = {
|
|
36
|
-
labelWidth: _propTypes.default.number,
|
|
37
|
-
labelInline: _propTypes.default.bool
|
|
38
|
-
};
|
|
39
|
-
var _default = FieldHelpStyle;
|
|
28
|
+
var _default = StyledFieldHelp;
|
|
40
29
|
exports.default = _default;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default } from "./field-help";
|
|
1
|
+
export { default } from "./field-help.component";
|
|
2
|
+
export type { FieldHelpProps } from "./field-help.component";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
export const defaultFocusableSelectors: "button:not([disabled]), [href], input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]";
|
|
2
|
-
export function
|
|
3
|
-
export function isRadio(element: any): any;
|
|
2
|
+
export function getNextElement(element: any, focusableElements: any, shiftKey: any): any;
|
|
4
3
|
export function setElementFocus(element: any): void;
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.setElementFocus = setElementFocus;
|
|
7
|
-
exports.
|
|
7
|
+
exports.getNextElement = exports.defaultFocusableSelectors = void 0;
|
|
8
8
|
const defaultFocusableSelectors = 'button:not([disabled]), [href], input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]';
|
|
9
9
|
exports.defaultFocusableSelectors = defaultFocusableSelectors;
|
|
10
10
|
|
|
@@ -45,19 +45,66 @@ const isRadio = element => {
|
|
|
45
45
|
return element.hasAttribute("type") && element.getAttribute("type") === "radio";
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
const getRadioElementToFocus = (groupName, shiftKey) => {
|
|
49
|
+
const buttonsInGroup = document.querySelectorAll(`input[type="radio"][name="${groupName}"]`);
|
|
50
|
+
const selectedButton = [...buttonsInGroup].find(button => button.checked);
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
if (selectedButton) {
|
|
53
|
+
return selectedButton;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return buttonsInGroup[shiftKey ? buttonsInGroup.length - 1 : 0];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const getNextElement = (element, focusableElements, shiftKey) => {
|
|
51
60
|
const currentIndex = focusableElements.indexOf(element);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
const increment = shiftKey ? -1 : 1;
|
|
62
|
+
let nextIndex = currentIndex;
|
|
63
|
+
let foundElement;
|
|
64
|
+
|
|
65
|
+
while (!foundElement) {
|
|
66
|
+
nextIndex += increment;
|
|
67
|
+
|
|
68
|
+
if (nextIndex < 0) {
|
|
69
|
+
nextIndex += focusableElements.length;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (nextIndex >= focusableElements.length) {
|
|
73
|
+
nextIndex -= focusableElements.length;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const nextElement = focusableElements[nextIndex];
|
|
77
|
+
|
|
78
|
+
if (nextElement === element) {
|
|
79
|
+
// guard in case there is only one focusable element (or only a single radio group) in the trap.
|
|
80
|
+
// If this happens we don't want to freeze the browser by looping forever, and it's OK to just focus
|
|
81
|
+
// the same element we're already on
|
|
82
|
+
return element;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (isRadio(nextElement)) {
|
|
86
|
+
// if we've reached a radio element we need to ensure we focus the correct button in its group
|
|
87
|
+
const nextElementGroupName = nextElement.getAttribute("name");
|
|
88
|
+
|
|
89
|
+
if (isRadio(element)) {
|
|
90
|
+
const groupName = element.getAttribute("name"); // if the name is different we're in a new group so can focus the appropriate button in it*/
|
|
91
|
+
|
|
92
|
+
if (nextElementGroupName !== groupName) {
|
|
93
|
+
foundElement = getRadioElementToFocus(nextElementGroupName, shiftKey);
|
|
94
|
+
} // otherwise we're still in the same radio group so need to continue the loop
|
|
55
95
|
|
|
56
|
-
|
|
57
|
-
|
|
96
|
+
} else {
|
|
97
|
+
// if we've moved into a radio group from a non-radio starting point, we still have to ensure we focus
|
|
98
|
+
// the correct button in the group
|
|
99
|
+
foundElement = getRadioElementToFocus(nextElementGroupName, shiftKey);
|
|
100
|
+
}
|
|
101
|
+
} else {
|
|
102
|
+
// if we've reached a non-radio element, we can focus it with no issues
|
|
103
|
+
foundElement = nextElement;
|
|
104
|
+
}
|
|
58
105
|
}
|
|
59
106
|
|
|
60
|
-
return
|
|
107
|
+
return foundElement;
|
|
61
108
|
};
|
|
62
109
|
|
|
63
|
-
exports.
|
|
110
|
+
exports.getNextElement = getNextElement;
|
|
@@ -27,7 +27,8 @@ const FocusTrap = ({
|
|
|
27
27
|
focusFirstElement,
|
|
28
28
|
bespokeTrap,
|
|
29
29
|
wrapperRef,
|
|
30
|
-
isOpen
|
|
30
|
+
isOpen,
|
|
31
|
+
additionalWrapperRefs
|
|
31
32
|
}) => {
|
|
32
33
|
const trapRef = (0, _react.useRef)(null);
|
|
33
34
|
const [focusableElements, setFocusableElements] = (0, _react.useState)();
|
|
@@ -45,19 +46,21 @@ const FocusTrap = ({
|
|
|
45
46
|
|
|
46
47
|
return Array.from(candidate).some((el, i) => el !== focusableElements[i]);
|
|
47
48
|
}, [focusableElements]);
|
|
49
|
+
const allRefs = [wrapperRef, ...additionalWrapperRefs].map(ref => ref === null || ref === void 0 ? void 0 : ref.current);
|
|
48
50
|
const updateFocusableElements = (0, _react.useCallback)(() => {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (hasNewInputs(elements)) {
|
|
55
|
-
setFocusableElements(Array.from(elements));
|
|
56
|
-
setFirstElement(elements[0]);
|
|
57
|
-
setLastElement(elements[elements.length - 1]);
|
|
51
|
+
const elements = [];
|
|
52
|
+
allRefs.forEach(ref => {
|
|
53
|
+
if (ref) {
|
|
54
|
+
elements.push(...Array.from(ref.querySelectorAll(_focusTrapUtils.defaultFocusableSelectors)).filter(el => Number(el.tabIndex) !== -1));
|
|
58
55
|
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (hasNewInputs(elements)) {
|
|
59
|
+
setFocusableElements(Array.from(elements));
|
|
60
|
+
setFirstElement(elements[0]);
|
|
61
|
+
setLastElement(elements[elements.length - 1]);
|
|
59
62
|
}
|
|
60
|
-
}, [hasNewInputs,
|
|
63
|
+
}, [hasNewInputs, allRefs]);
|
|
61
64
|
(0, _react.useEffect)(() => {
|
|
62
65
|
const observer = new MutationObserver(updateFocusableElements);
|
|
63
66
|
observer.observe(trapRef.current, {
|
|
@@ -95,20 +98,19 @@ const FocusTrap = ({
|
|
|
95
98
|
ev.preventDefault();
|
|
96
99
|
} else if (ev.shiftKey) {
|
|
97
100
|
/* shift + tab */
|
|
98
|
-
|
|
99
|
-
lastElement.focus();
|
|
100
|
-
ev.preventDefault();
|
|
101
|
-
} // If current element is radio button -
|
|
102
|
-
// find next non radio button element
|
|
103
|
-
|
|
101
|
+
let elementToFocus;
|
|
104
102
|
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
ev.
|
|
103
|
+
if (activeElement === wrapperRef.current) {
|
|
104
|
+
elementToFocus = (0, _focusTrapUtils.getNextElement)(firstElement, focusableElements, ev.shiftKey);
|
|
105
|
+
} else {
|
|
106
|
+
elementToFocus = (0, _focusTrapUtils.getNextElement)(activeElement, focusableElements, ev.shiftKey);
|
|
109
107
|
}
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
|
|
109
|
+
(0, _focusTrapUtils.setElementFocus)(elementToFocus);
|
|
110
|
+
ev.preventDefault();
|
|
111
|
+
} else {
|
|
112
|
+
const elementToFocus = (0, _focusTrapUtils.getNextElement)(activeElement, focusableElements, ev.shiftKey);
|
|
113
|
+
(0, _focusTrapUtils.setElementFocus)(elementToFocus);
|
|
112
114
|
ev.preventDefault();
|
|
113
115
|
}
|
|
114
116
|
}
|
|
@@ -196,7 +198,15 @@ FocusTrap.propTypes = {
|
|
|
196
198
|
}),
|
|
197
199
|
|
|
198
200
|
/* whether the modal (etc.) component that the focus trap is inside is open or not */
|
|
199
|
-
isOpen: _propTypes.default.bool
|
|
201
|
+
isOpen: _propTypes.default.bool,
|
|
202
|
+
|
|
203
|
+
/** an optional array of refs to containers whose content should also be reachable from the FocusTrap */
|
|
204
|
+
additionalWrapperRefs: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
205
|
+
current: _propTypes.default.any
|
|
206
|
+
}))
|
|
207
|
+
};
|
|
208
|
+
FocusTrap.defaultProps = {
|
|
209
|
+
additionalWrapperRefs: []
|
|
200
210
|
};
|
|
201
211
|
var _default = FocusTrap;
|
|
202
212
|
exports.default = _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var _enzymeAdapterReact = _interopRequireDefault(require("@wojtekmaj/enzyme-adapter-react-17"));
|
|
3
|
+
var _jestFetchMock = require("jest-fetch-mock");
|
|
6
4
|
|
|
7
5
|
var _mockMatchMedia = require("./mock-match-media");
|
|
8
6
|
|
|
@@ -10,11 +8,6 @@ var _mockResizeObserver = _interopRequireDefault(require("./mock-resize-observer
|
|
|
10
8
|
|
|
11
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
(0, _jestFetchMock.enableFetchMocks)();
|
|
15
12
|
(0, _mockResizeObserver.default)();
|
|
16
|
-
(0, _mockMatchMedia.
|
|
17
|
-
|
|
18
|
-
_enzyme.default.configure({
|
|
19
|
-
adapter: new _enzymeAdapterReact.default()
|
|
20
|
-
});
|
|
13
|
+
(0, _mockMatchMedia.setupMatchMediaMock)();
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.mockMatchMedia = exports.
|
|
6
|
+
exports.mockMatchMedia = exports.setupMatchMediaMock = void 0;
|
|
7
7
|
let mocked = false;
|
|
8
8
|
let _matches = false;
|
|
9
9
|
const removeListener = jest.fn();
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const setupMatchMediaMock = () => {
|
|
12
12
|
if (!global.window) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
@@ -29,11 +29,11 @@ const setup = () => {
|
|
|
29
29
|
mocked = true;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
exports.
|
|
32
|
+
exports.setupMatchMediaMock = setupMatchMediaMock;
|
|
33
33
|
|
|
34
34
|
const mockMatchMedia = matches => {
|
|
35
35
|
if (!mocked) {
|
|
36
|
-
throw new Error("window.matchMedia has not been mocked. Did you call
|
|
36
|
+
throw new Error("window.matchMedia has not been mocked. Did you call setupMatchMediaMock()?");
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
_matches = matches;
|
|
@@ -42,6 +42,15 @@ Alert.propTypes = {
|
|
|
42
42
|
"disableEscKey": _propTypes.default.bool,
|
|
43
43
|
"disableFocusTrap": _propTypes.default.bool,
|
|
44
44
|
"enableBackgroundUI": _propTypes.default.bool,
|
|
45
|
+
"focusableContainers": _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
46
|
+
"current": function (props, propName) {
|
|
47
|
+
if (props[propName] == null) {
|
|
48
|
+
return new Error("Prop '" + propName + "' is required but wasn't specified");
|
|
49
|
+
} else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
|
|
50
|
+
return new Error("Expected prop '" + propName + "' to be of type Element");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
})),
|
|
45
54
|
"focusFirstElement": _propTypes.default.shape({
|
|
46
55
|
"current": function (props, propName) {
|
|
47
56
|
if (props[propName] == null) {
|
|
@@ -55,6 +55,7 @@ const Dialog = ({
|
|
|
55
55
|
help,
|
|
56
56
|
role = "dialog",
|
|
57
57
|
contentPadding = {},
|
|
58
|
+
focusableContainers,
|
|
58
59
|
...rest
|
|
59
60
|
}) => {
|
|
60
61
|
const locale = (0, _useLocale.default)();
|
|
@@ -180,7 +181,8 @@ const Dialog = ({
|
|
|
180
181
|
focusFirstElement: focusFirstElement,
|
|
181
182
|
bespokeTrap: bespokeFocusTrap,
|
|
182
183
|
wrapperRef: dialogRef,
|
|
183
|
-
isOpen: open
|
|
184
|
+
isOpen: open,
|
|
185
|
+
additionalWrapperRefs: focusableContainers
|
|
184
186
|
}, /*#__PURE__*/_react.default.createElement(_dialog.DialogStyle, _extends({
|
|
185
187
|
"aria-modal": true,
|
|
186
188
|
ref: dialogRef,
|
|
@@ -271,7 +273,12 @@ Dialog.propTypes = {
|
|
|
271
273
|
p: _propTypes.default.oneOf([0, 1, 2, 3, 4, 5, 6, 7, 8]),
|
|
272
274
|
px: _propTypes.default.oneOf([0, 1, 2, 3, 4, 5, 6, 7, 8]),
|
|
273
275
|
py: _propTypes.default.oneOf([0, 1, 2, 3, 4, 5, 6, 7, 8])
|
|
274
|
-
})
|
|
276
|
+
}),
|
|
277
|
+
|
|
278
|
+
/** an optional array of refs to containers whose content should also be reachable by tabbing from the dialog */
|
|
279
|
+
focusableContainers: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
280
|
+
current: _propTypes.default.any
|
|
281
|
+
}))
|
|
275
282
|
};
|
|
276
283
|
Dialog.defaultProps = {
|
|
277
284
|
size: "medium",
|
|
@@ -59,6 +59,8 @@ export interface DialogProps extends ModalProps {
|
|
|
59
59
|
role?: string;
|
|
60
60
|
/** Padding to be set on the Dialog content */
|
|
61
61
|
contentPadding?: ContentPaddingInterface;
|
|
62
|
+
/** an optional array of refs to containers whose content should also be reachable by tabbing from the dialog */
|
|
63
|
+
focusableContainers?: React.MutableRefObject<HTMLElement>[];
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
declare function Dialog(props: DialogProps): JSX.Element;
|
|
@@ -56,6 +56,7 @@ const DialogFullScreen = ({
|
|
|
56
56
|
contentRef,
|
|
57
57
|
help,
|
|
58
58
|
role = "dialog",
|
|
59
|
+
focusableContainers,
|
|
59
60
|
...rest
|
|
60
61
|
}) => {
|
|
61
62
|
const locale = (0, _useLocale.default)();
|
|
@@ -110,7 +111,8 @@ const DialogFullScreen = ({
|
|
|
110
111
|
autoFocus: !disableAutoFocus,
|
|
111
112
|
focusFirstElement: focusFirstElement,
|
|
112
113
|
wrapperRef: dialogRef,
|
|
113
|
-
isOpen: open
|
|
114
|
+
isOpen: open,
|
|
115
|
+
additionalWrapperRefs: focusableContainers
|
|
114
116
|
}, /*#__PURE__*/_react.default.createElement(_dialogFullScreen.default, _extends({
|
|
115
117
|
"aria-modal": role === "dialog" ? true : undefined
|
|
116
118
|
}, ariaProps, {
|
|
@@ -194,7 +196,12 @@ DialogFullScreen.propTypes = {
|
|
|
194
196
|
})]),
|
|
195
197
|
|
|
196
198
|
/** The ARIA role to be applied to the DialogFullscreen container */
|
|
197
|
-
role: _propTypes.default.string
|
|
199
|
+
role: _propTypes.default.string,
|
|
200
|
+
|
|
201
|
+
/** an optional array of refs to containers whose content should also be reachable by tabbing from the dialog */
|
|
202
|
+
focusableContainers: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
203
|
+
current: _propTypes.default.any
|
|
204
|
+
}))
|
|
198
205
|
};
|
|
199
206
|
var _default = DialogFullScreen;
|
|
200
207
|
exports.default = _default;
|
|
@@ -41,6 +41,8 @@ export interface DialogFullScreenProps extends ModalProps {
|
|
|
41
41
|
title?: React.ReactNode;
|
|
42
42
|
/** The ARIA role to be applied to the DialogFullscreen container */
|
|
43
43
|
role?: string;
|
|
44
|
+
/** an optional array of refs to containers whose content should also be reachable by tabbing from the dialog */
|
|
45
|
+
focusableContainers?: React.MutableRefObject<HTMLElement>[];
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
declare function DialogFullScreen(props: DialogFullScreenProps): JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { SpaceProps, GridProps } from "styled-system";
|
|
3
|
+
export interface GridContainerProps extends SpaceProps, GridProps, React.HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
/** Defines the Components to be rendered within the GridContainer. Requires GridItemProps */
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare const GridContainer: (props: GridContainerProps) => JSX.Element;
|
|
8
|
+
export default GridContainer;
|