carbon-react 110.0.3 → 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.
@@ -1,3 +1,4 @@
1
- export const defaultFocusableSelectors: "button:not([disabled]), [href], input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]";
2
- export function getNextElement(element: any, focusableElements: any, shiftKey: any): any;
3
- export function setElementFocus(element: any): void;
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 };
@@ -1,8 +1,8 @@
1
1
  const defaultFocusableSelectors = 'button:not([disabled]), [href], input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]';
2
+ const INTERVAL = 10;
3
+ const MAX_TIME = 100;
2
4
 
3
- const waitForVisibleAndFocus = element => {
4
- const INTERVAL = 10;
5
- const MAX_TIME = 100;
5
+ const setElementFocus = element => {
6
6
  let timeSoFar = 0;
7
7
 
8
8
  const stylesMatch = () => {
@@ -24,15 +24,6 @@ const waitForVisibleAndFocus = element => {
24
24
  check();
25
25
  };
26
26
 
27
- function setElementFocus(element) {
28
- if (typeof element === "function") {
29
- element();
30
- } else {
31
- const el = element.current || element;
32
- waitForVisibleAndFocus(el);
33
- }
34
- }
35
-
36
27
  const isRadio = element => {
37
28
  return element.hasAttribute("type") && element.getAttribute("type") === "radio";
38
29
  };
@@ -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;
@@ -1,8 +1,8 @@
1
- import React, { useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
1
+ import React, { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
2
2
  import PropTypes from "prop-types";
3
3
  import { defaultFocusableSelectors, getNextElement, setElementFocus } from "./focus-trap-utils";
4
4
  import { ModalContext } from "../../components/modal/modal.component";
5
- import usePrevious from "../../hooks/__internal__/usePrevious";
5
+ import usePrevious from "../../hooks/__internal__/usePrevious"; // TODO investigate why React.RefObject<T> produces a failed prop type when current = null
6
6
 
7
7
  const FocusTrap = ({
8
8
  children,
@@ -29,7 +29,8 @@ const FocusTrap = ({
29
29
 
30
30
  return Array.from(candidate).some((el, i) => el !== focusableElements[i]);
31
31
  }, [focusableElements]);
32
- const allRefs = [wrapperRef, ...additionalWrapperRefs].map(ref => ref === null || ref === void 0 ? void 0 : ref.current);
32
+ const trapWrappers = useMemo(() => additionalWrapperRefs !== null && additionalWrapperRefs !== void 0 && additionalWrapperRefs.length ? [wrapperRef, ...additionalWrapperRefs] : [wrapperRef], [additionalWrapperRefs, wrapperRef]);
33
+ const allRefs = trapWrappers.map(ref => ref === null || ref === void 0 ? void 0 : ref.current);
33
34
  const updateFocusableElements = useCallback(() => {
34
35
  const elements = [];
35
36
  allRefs.forEach(ref => {
@@ -46,14 +47,18 @@ const FocusTrap = ({
46
47
  }, [hasNewInputs, allRefs]);
47
48
  useEffect(() => {
48
49
  const observer = new MutationObserver(updateFocusableElements);
49
- observer.observe(trapRef.current, {
50
- subtree: true,
51
- childList: true,
52
- attributes: true,
53
- characterData: true
50
+ trapWrappers.forEach(wrapper => {
51
+ if (wrapper !== null && wrapper !== void 0 && wrapper.current) {
52
+ observer.observe(wrapper === null || wrapper === void 0 ? void 0 : wrapper.current, {
53
+ subtree: true,
54
+ childList: true,
55
+ attributes: true,
56
+ characterData: true
57
+ });
58
+ }
54
59
  });
55
60
  return () => observer.disconnect();
56
- }, [updateFocusableElements]);
61
+ }, [updateFocusableElements, trapWrappers]);
57
62
  useLayoutEffect(() => {
58
63
  updateFocusableElements();
59
64
  }, [children, updateFocusableElements]);
@@ -61,7 +66,8 @@ const FocusTrap = ({
61
66
  const prevShouldSetFocus = usePrevious(shouldSetFocus);
62
67
  useEffect(() => {
63
68
  if (shouldSetFocus && !prevShouldSetFocus) {
64
- setElementFocus(focusFirstElement || (wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current));
69
+ const candidateFirstElement = focusFirstElement && "current" in focusFirstElement ? focusFirstElement.current : focusFirstElement;
70
+ setElementFocus(candidateFirstElement || (wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current));
65
71
  }
66
72
  }, [shouldSetFocus, prevShouldSetFocus, focusFirstElement, wrapperRef]);
67
73
  useEffect(() => {
@@ -71,19 +77,17 @@ const FocusTrap = ({
71
77
  return;
72
78
  }
73
79
 
74
- const {
75
- activeElement
76
- } = document;
80
+ const activeElement = document.activeElement;
77
81
 
78
82
  if (ev.key === "Tab") {
79
- if (!focusableElements.length) {
83
+ if (!(focusableElements !== null && focusableElements !== void 0 && focusableElements.length)) {
80
84
  /* Block the trap */
81
85
  ev.preventDefault();
82
86
  } else if (ev.shiftKey) {
83
87
  /* shift + tab */
84
88
  let elementToFocus;
85
89
 
86
- if (activeElement === wrapperRef.current) {
90
+ if (activeElement === (wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current)) {
87
91
  elementToFocus = getNextElement(firstElement, focusableElements, ev.shiftKey);
88
92
  } else {
89
93
  elementToFocus = getNextElement(activeElement, focusableElements, ev.shiftKey);
@@ -99,9 +103,9 @@ const FocusTrap = ({
99
103
  }
100
104
  };
101
105
 
102
- document.addEventListener("keydown", trapFn);
106
+ document.addEventListener("keydown", trapFn, true);
103
107
  return function cleanup() {
104
- document.removeEventListener("keydown", trapFn);
108
+ document.removeEventListener("keydown", trapFn, true);
105
109
  };
106
110
  }, [firstElement, lastElement, focusableElements, bespokeTrap, wrapperRef]);
107
111
  const updateCurrentFocusedElement = useCallback(() => {
@@ -153,7 +157,10 @@ const FocusTrap = ({
153
157
 
154
158
 
155
159
  const clonedChildren = React.Children.map(children, child => {
156
- return /*#__PURE__*/React.cloneElement(child, focusProps(child.props.tabIndex === undefined));
160
+ var _focusableChild$props;
161
+
162
+ const focusableChild = child;
163
+ return /*#__PURE__*/React.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));
157
164
  });
158
165
  return /*#__PURE__*/React.createElement("div", {
159
166
  ref: trapRef
@@ -161,33 +168,42 @@ const FocusTrap = ({
161
168
  };
162
169
 
163
170
  FocusTrap.propTypes = {
164
- children: PropTypes.node.isRequired,
165
-
166
- /** flag to set focus automatically on first render */
167
- autoFocus: PropTypes.bool,
168
-
169
- /** provide a custom first element to focus */
170
- focusFirstElement: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
171
- current: PropTypes.any
171
+ "additionalWrapperRefs": PropTypes.arrayOf(PropTypes.shape({
172
+ "current": function (props, propName) {
173
+ if (props[propName] == null) {
174
+ return null;
175
+ } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
176
+ return new Error("Expected prop '" + propName + "' to be of type Element");
177
+ }
178
+ }
179
+ })),
180
+ "autoFocus": PropTypes.bool,
181
+ "bespokeTrap": PropTypes.func,
182
+ "children": PropTypes.node,
183
+ "focusFirstElement": PropTypes.oneOfType([function (props, propName) {
184
+ if (props[propName] == null) {
185
+ return new Error("Prop '" + propName + "' is required but wasn't specified");
186
+ } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
187
+ return new Error("Expected prop '" + propName + "' to be of type Element");
188
+ }
189
+ }, PropTypes.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
+ }
172
197
  })]),
173
-
174
- /** a custom callback that will override the default focus trap behaviour */
175
- bespokeTrap: PropTypes.func,
176
-
177
- /** a ref to the container wrapping the focusable elements */
178
- wrapperRef: PropTypes.shape({
179
- current: PropTypes.any
180
- }),
181
-
182
- /* whether the modal (etc.) component that the focus trap is inside is open or not */
183
- isOpen: PropTypes.bool,
184
-
185
- /** an optional array of refs to containers whose content should also be reachable from the FocusTrap */
186
- additionalWrapperRefs: PropTypes.arrayOf(PropTypes.shape({
187
- current: PropTypes.any
188
- }))
189
- };
190
- FocusTrap.defaultProps = {
191
- additionalWrapperRefs: []
198
+ "isOpen": PropTypes.bool,
199
+ "wrapperRef": PropTypes.shape({
200
+ "current": function (props, propName) {
201
+ if (props[propName] == null) {
202
+ return null;
203
+ } else if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {
204
+ return new Error("Expected prop '" + propName + "' to be of type Element");
205
+ }
206
+ }
207
+ })
192
208
  };
193
209
  export default FocusTrap;
@@ -0,0 +1,2 @@
1
+ export { default } from "./focus-trap.component";
2
+ export type { FocusTrapProps } from "./focus-trap.component";
@@ -35,9 +35,9 @@ const Dialog = ({
35
35
  ...rest
36
36
  }) => {
37
37
  const locale = useLocale();
38
- const dialogRef = useRef();
39
- const innerContentRef = useRef();
40
- const titleRef = useRef();
38
+ const dialogRef = useRef(null);
39
+ const innerContentRef = useRef(null);
40
+ const titleRef = useRef(null);
41
41
  const listenersAdded = useRef(false);
42
42
  const {
43
43
  current: titleId
@@ -36,8 +36,8 @@ const DialogFullScreen = ({
36
36
  ...rest
37
37
  }) => {
38
38
  const locale = useLocale();
39
- const dialogRef = useRef();
40
- const headingRef = useRef();
39
+ const dialogRef = useRef(null);
40
+ const headingRef = useRef(null);
41
41
  const {
42
42
  current: titleId
43
43
  } = useRef(createGuid());
@@ -6,6 +6,10 @@ import StyledFullScreenHeading from "../../__internal__/full-screen-heading/full
6
6
  import { StyledHeader, StyledHeaderContent, StyledHeading } from "../heading/heading.style";
7
7
  import { StyledForm } from "../form/form.style";
8
8
  const StyledDialogFullScreen = styled.div`
9
+ :focus {
10
+ outline: none;
11
+ }
12
+
9
13
  background-color: var(--colorsUtilityMajor025);
10
14
  height: 100%;
11
15
  left: 0;
@@ -33,7 +33,7 @@ const Sidebar = /*#__PURE__*/React.forwardRef(({
33
33
  const {
34
34
  current: titleId
35
35
  } = useRef(createGuid());
36
- let sidebarRef = useRef();
36
+ let sidebarRef = useRef(null);
37
37
  if (ref) sidebarRef = ref;
38
38
 
39
39
  const closeIcon = () => {
@@ -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
- export const defaultFocusableSelectors: "button:not([disabled]), [href], input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]";
2
- export function getNextElement(element: any, focusableElements: any, shiftKey: any): any;
3
- export function setElementFocus(element: any): void;
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 = 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 waitForVisibleAndFocus = element => {
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
- function setElementFocus(element) {
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 allRefs = [wrapperRef, ...additionalWrapperRefs].map(ref => ref === null || ref === void 0 ? void 0 : ref.current);
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
- observer.observe(trapRef.current, {
67
- subtree: true,
68
- childList: true,
69
- attributes: true,
70
- characterData: true
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
- (0, _focusTrapUtils.setElementFocus)(focusFirstElement || (wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current));
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
- return /*#__PURE__*/_react.default.cloneElement(child, focusProps(child.props.tabIndex === undefined));
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
- children: _propTypes.default.node.isRequired,
183
-
184
- /** flag to set focus automatically on first render */
185
- autoFocus: _propTypes.default.bool,
186
-
187
- /** provide a custom first element to focus */
188
- focusFirstElement: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.shape({
189
- current: _propTypes.default.any
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
- /** a custom callback that will override the default focus trap behaviour */
193
- bespokeTrap: _propTypes.default.func,
194
-
195
- /** a ref to the container wrapping the focusable elements */
196
- wrapperRef: _propTypes.default.shape({
197
- current: _propTypes.default.any
198
- }),
199
-
200
- /* whether the modal (etc.) component that the focus trap is inside is open or not */
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;
@@ -0,0 +1,2 @@
1
+ export { default } from "./focus-trap.component";
2
+ export type { FocusTrapProps } from "./focus-trap.component";
@@ -59,9 +59,9 @@ const Dialog = ({
59
59
  ...rest
60
60
  }) => {
61
61
  const locale = (0, _useLocale.default)();
62
- const dialogRef = (0, _react.useRef)();
63
- const innerContentRef = (0, _react.useRef)();
64
- const titleRef = (0, _react.useRef)();
62
+ const dialogRef = (0, _react.useRef)(null);
63
+ const innerContentRef = (0, _react.useRef)(null);
64
+ const titleRef = (0, _react.useRef)(null);
65
65
  const listenersAdded = (0, _react.useRef)(false);
66
66
  const {
67
67
  current: titleId
@@ -60,8 +60,8 @@ const DialogFullScreen = ({
60
60
  ...rest
61
61
  }) => {
62
62
  const locale = (0, _useLocale.default)();
63
- const dialogRef = (0, _react.useRef)();
64
- const headingRef = (0, _react.useRef)();
63
+ const dialogRef = (0, _react.useRef)(null);
64
+ const headingRef = (0, _react.useRef)(null);
65
65
  const {
66
66
  current: titleId
67
67
  } = (0, _react.useRef)((0, _guid.default)());
@@ -26,6 +26,10 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
26
26
  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; }
27
27
 
28
28
  const StyledDialogFullScreen = _styledComponents.default.div`
29
+ :focus {
30
+ outline: none;
31
+ }
32
+
29
33
  background-color: var(--colorsUtilityMajor025);
30
34
  height: 100%;
31
35
  left: 0;
@@ -61,7 +61,7 @@ const Sidebar = /*#__PURE__*/_react.default.forwardRef(({
61
61
  const {
62
62
  current: titleId
63
63
  } = (0, _react.useRef)((0, _guid.default)());
64
- let sidebarRef = (0, _react.useRef)();
64
+ let sidebarRef = (0, _react.useRef)(null);
65
65
  if (ref) sidebarRef = ref;
66
66
 
67
67
  const closeIcon = () => {
@@ -20,6 +20,11 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
20
20
  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; }
21
21
 
22
22
  const SidebarStyle = _styledComponents.default.div`
23
+ // prevents outline being added in safari
24
+ :focus {
25
+ outline: none;
26
+ }
27
+
23
28
  ${({
24
29
  onCancel,
25
30
  position,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "110.0.3",
3
+ "version": "110.0.4",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "engineStrict": true,
6
6
  "engines": {