carbon-react 110.0.1 → 110.0.4
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-utils.d.ts +4 -3
- package/esm/__internal__/focus-trap/focus-trap-utils.js +3 -12
- package/esm/__internal__/focus-trap/focus-trap.component.d.ts +19 -0
- package/esm/__internal__/focus-trap/focus-trap.component.js +61 -45
- package/esm/__internal__/focus-trap/index.d.ts +2 -0
- package/esm/__internal__/utils/helpers/tags/tags-specs/tags-specs.d.ts +1 -1
- package/esm/components/definition-list/__internal__/dl.context.d.ts +6 -0
- package/esm/components/definition-list/dd.component.d.ts +8 -0
- package/esm/components/definition-list/dd.component.js +310 -5
- package/esm/components/definition-list/definition-list.style.d.ts +22 -0
- package/esm/components/definition-list/definition-list.style.js +3 -4
- package/esm/components/definition-list/dl.component.d.ts +9 -0
- package/esm/components/definition-list/dl.component.js +323 -27
- package/esm/components/definition-list/dt.component.d.ts +8 -0
- package/esm/components/definition-list/dt.component.js +310 -5
- package/esm/components/definition-list/index.d.ts +6 -3
- package/esm/components/definition-list/index.js +2 -2
- package/esm/components/dialog/dialog.component.js +3 -3
- package/esm/components/dialog-full-screen/dialog-full-screen.component.js +2 -2
- package/esm/components/dialog-full-screen/dialog-full-screen.style.js +4 -0
- package/esm/components/flat-table/flat-table-row/flat-table-row.style.js +30 -2
- package/esm/components/modal/modal.component.d.ts +1 -20
- package/esm/components/modal/modal.component.js +8 -21
- package/esm/components/profile/index.d.ts +2 -1
- package/esm/components/profile/profile.component.d.ts +18 -0
- package/esm/components/profile/profile.component.js +8 -21
- package/esm/components/profile/profile.config.d.ts +55 -0
- package/esm/components/profile/profile.style.d.ts +16 -0
- package/esm/components/profile/profile.style.js +5 -14
- package/esm/components/sidebar/sidebar.component.js +1 -1
- package/esm/components/sidebar/sidebar.style.js +5 -0
- package/lib/__internal__/focus-trap/focus-trap-utils.d.ts +4 -3
- package/lib/__internal__/focus-trap/focus-trap-utils.js +5 -13
- package/lib/__internal__/focus-trap/focus-trap.component.d.ts +19 -0
- package/lib/__internal__/focus-trap/focus-trap.component.js +59 -43
- package/lib/__internal__/focus-trap/index.d.ts +2 -0
- package/lib/__internal__/utils/helpers/tags/tags-specs/tags-specs.d.ts +1 -1
- package/lib/components/definition-list/__internal__/dl.context.d.ts +6 -0
- package/lib/components/definition-list/dd.component.d.ts +8 -0
- package/lib/components/definition-list/dd.component.js +311 -7
- package/lib/components/definition-list/definition-list.style.d.ts +22 -0
- package/lib/components/definition-list/definition-list.style.js +3 -4
- package/lib/components/definition-list/dl.component.d.ts +9 -0
- package/lib/components/definition-list/dl.component.js +326 -28
- package/lib/components/definition-list/dt.component.d.ts +8 -0
- package/lib/components/definition-list/dt.component.js +311 -7
- package/lib/components/definition-list/index.d.ts +6 -3
- package/lib/components/definition-list/index.js +8 -8
- package/lib/components/dialog/dialog.component.js +3 -3
- package/lib/components/dialog-full-screen/dialog-full-screen.component.js +2 -2
- package/lib/components/dialog-full-screen/dialog-full-screen.style.js +4 -0
- package/lib/components/flat-table/flat-table-row/flat-table-row.style.js +30 -2
- package/lib/components/modal/modal.component.d.ts +1 -20
- package/lib/components/modal/modal.component.js +8 -20
- package/lib/components/profile/index.d.ts +2 -1
- package/lib/components/profile/profile.component.d.ts +18 -0
- package/lib/components/profile/profile.component.js +9 -24
- package/lib/components/profile/profile.config.d.ts +55 -0
- package/lib/components/profile/profile.style.d.ts +16 -0
- package/lib/components/profile/profile.style.js +5 -14
- package/lib/components/sidebar/sidebar.component.js +1 -1
- package/lib/components/sidebar/sidebar.style.js +5 -0
- package/package.json +1 -1
- package/esm/components/definition-list/dd.d.ts +0 -11
- package/esm/components/definition-list/dl.d.ts +0 -19
- package/esm/components/definition-list/dt.d.ts +0 -10
- package/esm/components/profile/profile.d.ts +0 -18
- package/lib/components/definition-list/dd.d.ts +0 -11
- package/lib/components/definition-list/dl.d.ts +0 -19
- package/lib/components/definition-list/dt.d.ts +0 -10
- package/lib/components/profile/profile.d.ts +0 -18
|
@@ -7,12 +7,12 @@ const ProfileNameStyle = styled.span`
|
|
|
7
7
|
font-weight: bold;
|
|
8
8
|
display: block;
|
|
9
9
|
font-size: ${({
|
|
10
|
-
size
|
|
10
|
+
size = "M"
|
|
11
11
|
}) => profileConfigSizes[size].nameSize};
|
|
12
12
|
`;
|
|
13
13
|
const ProfileEmailStyle = styled.span`
|
|
14
14
|
font-size: ${({
|
|
15
|
-
size
|
|
15
|
+
size = "M"
|
|
16
16
|
}) => profileConfigSizes[size].emailSize};
|
|
17
17
|
`;
|
|
18
18
|
const ProfileStyle = styled.div`
|
|
@@ -29,13 +29,13 @@ const ProfileDetailsStyle = styled.div`
|
|
|
29
29
|
display: inline-block;
|
|
30
30
|
margin-top: ${({
|
|
31
31
|
hasSrc,
|
|
32
|
-
size
|
|
32
|
+
size = "M"
|
|
33
33
|
}) => hasSrc ? profileConfigSizes[size].marginTop : ""};
|
|
34
34
|
line-height: ${({
|
|
35
|
-
size
|
|
35
|
+
size = "M"
|
|
36
36
|
}) => profileConfigSizes[size].lineHeight};
|
|
37
37
|
margin-left: ${({
|
|
38
|
-
size
|
|
38
|
+
size = "M"
|
|
39
39
|
}) => profileConfigSizes[size].marginLeft};
|
|
40
40
|
`;
|
|
41
41
|
const ProfileAvatarStyle = styled(Portrait)`
|
|
@@ -44,13 +44,4 @@ const ProfileAvatarStyle = styled(Portrait)`
|
|
|
44
44
|
ProfileStyle.defaultProps = {
|
|
45
45
|
theme: baseTheme
|
|
46
46
|
};
|
|
47
|
-
ProfileNameStyle.defaultProps = {
|
|
48
|
-
size: "M"
|
|
49
|
-
};
|
|
50
|
-
ProfileEmailStyle.defaultProps = {
|
|
51
|
-
size: "M"
|
|
52
|
-
};
|
|
53
|
-
ProfileDetailsStyle.defaultProps = {
|
|
54
|
-
size: "M"
|
|
55
|
-
};
|
|
56
47
|
export { ProfileStyle, ProfileNameStyle, ProfileDetailsStyle, ProfileAvatarStyle, ProfileEmailStyle };
|
|
@@ -3,6 +3,11 @@ import baseTheme from "../../style/themes/base";
|
|
|
3
3
|
import StyledIconButton from "../icon-button/icon-button.style";
|
|
4
4
|
import { SIDEBAR_SIZES_CSS } from "./sidebar.config";
|
|
5
5
|
const SidebarStyle = styled.div`
|
|
6
|
+
// prevents outline being added in safari
|
|
7
|
+
:focus {
|
|
8
|
+
outline: none;
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
${({
|
|
7
12
|
onCancel,
|
|
8
13
|
position,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
declare const defaultFocusableSelectors = "button:not([disabled]), [href], input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]";
|
|
2
|
+
declare const setElementFocus: (element: HTMLElement) => void;
|
|
3
|
+
declare const getNextElement: (element: HTMLElement, focusableElements: HTMLElement[], shiftKey: boolean) => HTMLElement;
|
|
4
|
+
export { defaultFocusableSelectors, getNextElement, setElementFocus };
|
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.setElementFocus =
|
|
7
|
-
exports.getNextElement = exports.defaultFocusableSelectors = void 0;
|
|
6
|
+
exports.setElementFocus = exports.getNextElement = exports.defaultFocusableSelectors = void 0;
|
|
8
7
|
const defaultFocusableSelectors = 'button:not([disabled]), [href], input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]';
|
|
9
8
|
exports.defaultFocusableSelectors = defaultFocusableSelectors;
|
|
9
|
+
const INTERVAL = 10;
|
|
10
|
+
const MAX_TIME = 100;
|
|
10
11
|
|
|
11
|
-
const
|
|
12
|
-
const INTERVAL = 10;
|
|
13
|
-
const MAX_TIME = 100;
|
|
12
|
+
const setElementFocus = element => {
|
|
14
13
|
let timeSoFar = 0;
|
|
15
14
|
|
|
16
15
|
const stylesMatch = () => {
|
|
@@ -32,14 +31,7 @@ const waitForVisibleAndFocus = element => {
|
|
|
32
31
|
check();
|
|
33
32
|
};
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
if (typeof element === "function") {
|
|
37
|
-
element();
|
|
38
|
-
} else {
|
|
39
|
-
const el = element.current || element;
|
|
40
|
-
waitForVisibleAndFocus(el);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
34
|
+
exports.setElementFocus = setElementFocus;
|
|
43
35
|
|
|
44
36
|
const isRadio = element => {
|
|
45
37
|
return element.hasAttribute("type") && element.getAttribute("type") === "radio";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
declare type CustomRefObject<T> = {
|
|
3
|
+
current?: T | null;
|
|
4
|
+
};
|
|
5
|
+
export interface FocusTrapProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
autoFocus?: boolean;
|
|
8
|
+
/** provide a custom first element to focus */
|
|
9
|
+
focusFirstElement?: CustomRefObject<HTMLElement> | HTMLElement;
|
|
10
|
+
/** a custom callback that will override the default focus trap behaviour */
|
|
11
|
+
bespokeTrap?: (ev: KeyboardEvent, firstElement?: HTMLElement, lastElement?: HTMLElement) => void;
|
|
12
|
+
/** a ref to the container wrapping the focusable elements */
|
|
13
|
+
wrapperRef?: CustomRefObject<HTMLElement>;
|
|
14
|
+
isOpen?: boolean;
|
|
15
|
+
/** an optional array of refs to containers whose content should also be reachable from the FocusTrap */
|
|
16
|
+
additionalWrapperRefs?: CustomRefObject<HTMLElement>[];
|
|
17
|
+
}
|
|
18
|
+
declare const FocusTrap: ({ children, autoFocus, focusFirstElement, bespokeTrap, wrapperRef, isOpen, additionalWrapperRefs, }: FocusTrapProps) => JSX.Element;
|
|
19
|
+
export default FocusTrap;
|
|
@@ -46,7 +46,8 @@ const FocusTrap = ({
|
|
|
46
46
|
|
|
47
47
|
return Array.from(candidate).some((el, i) => el !== focusableElements[i]);
|
|
48
48
|
}, [focusableElements]);
|
|
49
|
-
const
|
|
49
|
+
const trapWrappers = (0, _react.useMemo)(() => additionalWrapperRefs !== null && additionalWrapperRefs !== void 0 && additionalWrapperRefs.length ? [wrapperRef, ...additionalWrapperRefs] : [wrapperRef], [additionalWrapperRefs, wrapperRef]);
|
|
50
|
+
const allRefs = trapWrappers.map(ref => ref === null || ref === void 0 ? void 0 : ref.current);
|
|
50
51
|
const updateFocusableElements = (0, _react.useCallback)(() => {
|
|
51
52
|
const elements = [];
|
|
52
53
|
allRefs.forEach(ref => {
|
|
@@ -63,14 +64,18 @@ const FocusTrap = ({
|
|
|
63
64
|
}, [hasNewInputs, allRefs]);
|
|
64
65
|
(0, _react.useEffect)(() => {
|
|
65
66
|
const observer = new MutationObserver(updateFocusableElements);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
trapWrappers.forEach(wrapper => {
|
|
68
|
+
if (wrapper !== null && wrapper !== void 0 && wrapper.current) {
|
|
69
|
+
observer.observe(wrapper === null || wrapper === void 0 ? void 0 : wrapper.current, {
|
|
70
|
+
subtree: true,
|
|
71
|
+
childList: true,
|
|
72
|
+
attributes: true,
|
|
73
|
+
characterData: true
|
|
74
|
+
});
|
|
75
|
+
}
|
|
71
76
|
});
|
|
72
77
|
return () => observer.disconnect();
|
|
73
|
-
}, [updateFocusableElements]);
|
|
78
|
+
}, [updateFocusableElements, trapWrappers]);
|
|
74
79
|
(0, _react.useLayoutEffect)(() => {
|
|
75
80
|
updateFocusableElements();
|
|
76
81
|
}, [children, updateFocusableElements]);
|
|
@@ -78,7 +83,8 @@ const FocusTrap = ({
|
|
|
78
83
|
const prevShouldSetFocus = (0, _usePrevious.default)(shouldSetFocus);
|
|
79
84
|
(0, _react.useEffect)(() => {
|
|
80
85
|
if (shouldSetFocus && !prevShouldSetFocus) {
|
|
81
|
-
|
|
86
|
+
const candidateFirstElement = focusFirstElement && "current" in focusFirstElement ? focusFirstElement.current : focusFirstElement;
|
|
87
|
+
(0, _focusTrapUtils.setElementFocus)(candidateFirstElement || (wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current));
|
|
82
88
|
}
|
|
83
89
|
}, [shouldSetFocus, prevShouldSetFocus, focusFirstElement, wrapperRef]);
|
|
84
90
|
(0, _react.useEffect)(() => {
|
|
@@ -88,19 +94,17 @@ const FocusTrap = ({
|
|
|
88
94
|
return;
|
|
89
95
|
}
|
|
90
96
|
|
|
91
|
-
const
|
|
92
|
-
activeElement
|
|
93
|
-
} = document;
|
|
97
|
+
const activeElement = document.activeElement;
|
|
94
98
|
|
|
95
99
|
if (ev.key === "Tab") {
|
|
96
|
-
if (!focusableElements.length) {
|
|
100
|
+
if (!(focusableElements !== null && focusableElements !== void 0 && focusableElements.length)) {
|
|
97
101
|
/* Block the trap */
|
|
98
102
|
ev.preventDefault();
|
|
99
103
|
} else if (ev.shiftKey) {
|
|
100
104
|
/* shift + tab */
|
|
101
105
|
let elementToFocus;
|
|
102
106
|
|
|
103
|
-
if (activeElement === wrapperRef.current) {
|
|
107
|
+
if (activeElement === (wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current)) {
|
|
104
108
|
elementToFocus = (0, _focusTrapUtils.getNextElement)(firstElement, focusableElements, ev.shiftKey);
|
|
105
109
|
} else {
|
|
106
110
|
elementToFocus = (0, _focusTrapUtils.getNextElement)(activeElement, focusableElements, ev.shiftKey);
|
|
@@ -116,9 +120,9 @@ const FocusTrap = ({
|
|
|
116
120
|
}
|
|
117
121
|
};
|
|
118
122
|
|
|
119
|
-
document.addEventListener("keydown", trapFn);
|
|
123
|
+
document.addEventListener("keydown", trapFn, true);
|
|
120
124
|
return function cleanup() {
|
|
121
|
-
document.removeEventListener("keydown", trapFn);
|
|
125
|
+
document.removeEventListener("keydown", trapFn, true);
|
|
122
126
|
};
|
|
123
127
|
}, [firstElement, lastElement, focusableElements, bespokeTrap, wrapperRef]);
|
|
124
128
|
const updateCurrentFocusedElement = (0, _react.useCallback)(() => {
|
|
@@ -170,7 +174,10 @@ const FocusTrap = ({
|
|
|
170
174
|
|
|
171
175
|
|
|
172
176
|
const clonedChildren = _react.default.Children.map(children, child => {
|
|
173
|
-
|
|
177
|
+
var _focusableChild$props;
|
|
178
|
+
|
|
179
|
+
const focusableChild = child;
|
|
180
|
+
return /*#__PURE__*/_react.default.cloneElement(focusableChild, focusProps((focusableChild === null || focusableChild === void 0 ? void 0 : (_focusableChild$props = focusableChild.props) === null || _focusableChild$props === void 0 ? void 0 : _focusableChild$props.tabIndex) === undefined));
|
|
174
181
|
});
|
|
175
182
|
|
|
176
183
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -179,34 +186,43 @@ const FocusTrap = ({
|
|
|
179
186
|
};
|
|
180
187
|
|
|
181
188
|
FocusTrap.propTypes = {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
189
|
+
"additionalWrapperRefs": _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
190
|
+
"current": function (props, propName) {
|
|
191
|
+
if (props[propName] == null) {
|
|
192
|
+
return null;
|
|
193
|
+
} else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
|
|
194
|
+
return new Error("Expected prop '" + propName + "' to be of type Element");
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
})),
|
|
198
|
+
"autoFocus": _propTypes.default.bool,
|
|
199
|
+
"bespokeTrap": _propTypes.default.func,
|
|
200
|
+
"children": _propTypes.default.node,
|
|
201
|
+
"focusFirstElement": _propTypes.default.oneOfType([function (props, propName) {
|
|
202
|
+
if (props[propName] == null) {
|
|
203
|
+
return new Error("Prop '" + propName + "' is required but wasn't specified");
|
|
204
|
+
} else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
|
|
205
|
+
return new Error("Expected prop '" + propName + "' to be of type Element");
|
|
206
|
+
}
|
|
207
|
+
}, _propTypes.default.shape({
|
|
208
|
+
"current": function (props, propName) {
|
|
209
|
+
if (props[propName] == null) {
|
|
210
|
+
return null;
|
|
211
|
+
} else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
|
|
212
|
+
return new Error("Expected prop '" + propName + "' to be of type Element");
|
|
213
|
+
}
|
|
214
|
+
}
|
|
190
215
|
})]),
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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: []
|
|
216
|
+
"isOpen": _propTypes.default.bool,
|
|
217
|
+
"wrapperRef": _propTypes.default.shape({
|
|
218
|
+
"current": function (props, propName) {
|
|
219
|
+
if (props[propName] == null) {
|
|
220
|
+
return null;
|
|
221
|
+
} else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
|
|
222
|
+
return new Error("Expected prop '" + propName + "' to be of type Element");
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
})
|
|
210
226
|
};
|
|
211
227
|
var _default = FocusTrap;
|
|
212
228
|
exports.default = _default;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ReactWrapper, ShallowWrapper } from "enzyme";
|
|
2
|
-
declare const elementsTagTest: (wrapper: ReactWrapper, elements: string[]) => void;
|
|
2
|
+
declare const elementsTagTest: (wrapper: ReactWrapper | ShallowWrapper, elements: string[]) => void;
|
|
3
3
|
declare const rootTagTest: (rootNode: ReactWrapper | ShallowWrapper, comp: string, elem?: string | undefined, role?: string | undefined) => void;
|
|
4
4
|
export { elementsTagTest, rootTagTest };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { SpaceProps } from "styled-system";
|
|
3
|
+
export interface DdProps extends SpaceProps {
|
|
4
|
+
/** Prop for what will render in the `<Dd></Dd>` tags */
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
}
|
|
7
|
+
declare const Dd: ({ children, ...rest }: DdProps) => JSX.Element;
|
|
8
|
+
export default Dd;
|