carbon-react 151.2.2 → 151.3.0

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.
Files changed (45) hide show
  1. package/esm/__internal__/dom/globals.d.ts +51 -0
  2. package/esm/__internal__/dom/globals.js +59 -0
  3. package/esm/__internal__/utils/helpers/events/events.d.ts +8 -0
  4. package/esm/__internal__/utils/helpers/events/events.js +12 -0
  5. package/esm/__spec_helper__/mock-element-scrollto.js +3 -0
  6. package/esm/__spec_helper__/mock-match-media.js +1 -1
  7. package/esm/__spec_helper__/mock-resize-observer.js +1 -1
  8. package/esm/components/action-popover/action-popover.component.js +7 -2
  9. package/esm/components/date/__internal__/date-picker/date-picker.component.js +11 -2
  10. package/esm/components/flat-table/__internal__/flat-table.context.d.ts +3 -1
  11. package/esm/components/flat-table/__internal__/flat-table.context.js +2 -1
  12. package/esm/components/flat-table/flat-table-row/flat-table-row.style.js +4 -1
  13. package/esm/components/flat-table/flat-table.component.js +10 -1
  14. package/esm/components/icon/icon.style.js +6 -4
  15. package/esm/components/menu/menu-full-screen/menu-full-screen.component.js +2 -1
  16. package/esm/components/modal/__internal__/modal-manager.js +18 -7
  17. package/esm/components/modal/modal.component.js +3 -1
  18. package/esm/components/multi-action-button/multi-action-button.component.js +6 -1
  19. package/esm/components/popover-container/popover-container.component.js +7 -2
  20. package/esm/components/split-button/split-button.component.js +5 -0
  21. package/esm/components/vertical-menu/vertical-menu-full-screen/vertical-menu-full-screen.component.js +3 -1
  22. package/esm/hooks/__internal__/useScrollBlock/scroll-block-manager.js +11 -4
  23. package/lib/__internal__/dom/globals.d.ts +51 -0
  24. package/lib/__internal__/dom/globals.js +67 -0
  25. package/lib/__internal__/utils/helpers/events/events.d.ts +8 -0
  26. package/lib/__internal__/utils/helpers/events/events.js +12 -0
  27. package/lib/__spec_helper__/mock-element-scrollto.js +3 -0
  28. package/lib/__spec_helper__/mock-match-media.js +1 -1
  29. package/lib/__spec_helper__/mock-resize-observer.js +1 -1
  30. package/lib/components/action-popover/action-popover.component.js +6 -1
  31. package/lib/components/date/__internal__/date-picker/date-picker.component.js +10 -1
  32. package/lib/components/flat-table/__internal__/flat-table.context.d.ts +3 -1
  33. package/lib/components/flat-table/__internal__/flat-table.context.js +2 -1
  34. package/lib/components/flat-table/flat-table-row/flat-table-row.style.js +4 -1
  35. package/lib/components/flat-table/flat-table.component.js +10 -1
  36. package/lib/components/icon/icon.style.js +6 -4
  37. package/lib/components/menu/menu-full-screen/menu-full-screen.component.js +2 -1
  38. package/lib/components/modal/__internal__/modal-manager.js +18 -7
  39. package/lib/components/modal/modal.component.js +3 -1
  40. package/lib/components/multi-action-button/multi-action-button.component.js +5 -0
  41. package/lib/components/popover-container/popover-container.component.js +6 -1
  42. package/lib/components/split-button/split-button.component.js +5 -0
  43. package/lib/components/vertical-menu/vertical-menu-full-screen/vertical-menu-full-screen.component.js +3 -1
  44. package/lib/hooks/__internal__/useScrollBlock/scroll-block-manager.js +12 -6
  45. package/package.json +2 -1
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Returns the global `window` object in a way that is friendly to SSR.
3
+ * This check can be avoided if you are sure that the code will only run in the browser.
4
+ * Some examples where you can ignore this:
5
+ * - `useEffect` hooks
6
+ * - `useLayoutEffect` hooks
7
+ * - Callbacks for event listeners
8
+ * - Files with the `"use-client"` directive
9
+ *
10
+ * Primarily, this is necessary when attempting to access the `window` object during rendering of components.
11
+ * However, even still, where possible, it is recommended to avoid accessing the `window` object during rendering
12
+ * because it can lead to hydration mismatches. This happens when the server-rendered HTML differs from what the
13
+ * client renders due to missing environment-specific data (e.g., `window.innerWidth` being undefined on the server).
14
+ *
15
+ * @returns The global `window` object, if it exists.
16
+ */
17
+ export declare function getWindow(): (Window & typeof globalThis) | undefined;
18
+ /**
19
+ * Returns the global `document` object in a way that is friendly to SSR.
20
+ * This check can be avoided if you are sure that the code will only run in the browser.
21
+ * Some examples where you can ignore this:
22
+ * - `useEffect` hooks
23
+ * - `useLayoutEffect` hooks
24
+ * - Callbacks for event listeners
25
+ * - Files with the `"use-client"` directive
26
+ *
27
+ * Primarily, this is necessary when attempting to access the `document` object during rendering of components.
28
+ * However, even still, where possible, it is recommended to avoid accessing the `document` object during rendering
29
+ * because it can lead to hydration mismatches. This happens when the server-rendered HTML differs from what the
30
+ * client renders due to missing environment-specific data (e.g., `document.children` being undefined on the server).
31
+ *
32
+ * @returns The global `document` object, if it exists.
33
+ */
34
+ export declare function getDocument(): Document | undefined;
35
+ /**
36
+ * Returns the global `navigator` object in a way that is friendly to SSR.
37
+ * This check can be avoided if you are sure that the code will only run in the browser.
38
+ * Some examples where you can ignore this:
39
+ * - `useEffect` hooks
40
+ * - `useLayoutEffect` hooks
41
+ * - Callbacks for event listeners
42
+ * - Files with the `"use-client"` directive
43
+ *
44
+ * Primarily, this is necessary when attempting to access the `navigator` object during rendering of components.
45
+ * However, even still, where possible, it is recommended to avoid accessing the `navigator` object during rendering
46
+ * because it can lead to hydration mismatches. This happens when the server-rendered HTML differs from what the
47
+ * client renders due to missing environment-specific data (e.g., `navigator.userAgent` being undefined on the server).
48
+ *
49
+ * @returns The global `navigator` object, if it exists.
50
+ */
51
+ export declare function getNavigator(): Navigator | undefined;
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Returns the global `window` object in a way that is friendly to SSR.
3
+ * This check can be avoided if you are sure that the code will only run in the browser.
4
+ * Some examples where you can ignore this:
5
+ * - `useEffect` hooks
6
+ * - `useLayoutEffect` hooks
7
+ * - Callbacks for event listeners
8
+ * - Files with the `"use-client"` directive
9
+ *
10
+ * Primarily, this is necessary when attempting to access the `window` object during rendering of components.
11
+ * However, even still, where possible, it is recommended to avoid accessing the `window` object during rendering
12
+ * because it can lead to hydration mismatches. This happens when the server-rendered HTML differs from what the
13
+ * client renders due to missing environment-specific data (e.g., `window.innerWidth` being undefined on the server).
14
+ *
15
+ * @returns The global `window` object, if it exists.
16
+ */
17
+ export function getWindow() {
18
+ return typeof window !== "undefined" ? window : undefined;
19
+ }
20
+
21
+ /**
22
+ * Returns the global `document` object in a way that is friendly to SSR.
23
+ * This check can be avoided if you are sure that the code will only run in the browser.
24
+ * Some examples where you can ignore this:
25
+ * - `useEffect` hooks
26
+ * - `useLayoutEffect` hooks
27
+ * - Callbacks for event listeners
28
+ * - Files with the `"use-client"` directive
29
+ *
30
+ * Primarily, this is necessary when attempting to access the `document` object during rendering of components.
31
+ * However, even still, where possible, it is recommended to avoid accessing the `document` object during rendering
32
+ * because it can lead to hydration mismatches. This happens when the server-rendered HTML differs from what the
33
+ * client renders due to missing environment-specific data (e.g., `document.children` being undefined on the server).
34
+ *
35
+ * @returns The global `document` object, if it exists.
36
+ */
37
+ export function getDocument() {
38
+ return typeof document !== "undefined" ? document : undefined;
39
+ }
40
+
41
+ /**
42
+ * Returns the global `navigator` object in a way that is friendly to SSR.
43
+ * This check can be avoided if you are sure that the code will only run in the browser.
44
+ * Some examples where you can ignore this:
45
+ * - `useEffect` hooks
46
+ * - `useLayoutEffect` hooks
47
+ * - Callbacks for event listeners
48
+ * - Files with the `"use-client"` directive
49
+ *
50
+ * Primarily, this is necessary when attempting to access the `navigator` object during rendering of components.
51
+ * However, even still, where possible, it is recommended to avoid accessing the `navigator` object during rendering
52
+ * because it can lead to hydration mismatches. This happens when the server-rendered HTML differs from what the
53
+ * client renders due to missing environment-specific data (e.g., `navigator.userAgent` being undefined on the server).
54
+ *
55
+ * @returns The global `navigator` object, if it exists.
56
+ */
57
+ export function getNavigator() {
58
+ return typeof navigator !== "undefined" ? navigator : undefined;
59
+ }
@@ -71,6 +71,14 @@ declare const Events: {
71
71
  * Determines if the key pressed is the end key
72
72
  * */
73
73
  isEndKey: (ev: React.KeyboardEvent | KeyboardEvent) => boolean;
74
+ /**
75
+ * Determines if the key pressed is the page up key
76
+ * */
77
+ isPageUpKey: (ev: React.KeyboardEvent | KeyboardEvent) => boolean;
78
+ /**
79
+ * Determines if the key pressed is the page down key
80
+ * */
81
+ isPageDownKey: (ev: React.KeyboardEvent | KeyboardEvent) => boolean;
74
82
  /**
75
83
  * Gets the event's path which is an array of the objects on which listeners will be invoked.
76
84
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath
@@ -103,6 +103,18 @@ const Events = {
103
103
  isEndKey: ev => {
104
104
  return ev.key === "End";
105
105
  },
106
+ /**
107
+ * Determines if the key pressed is the page up key
108
+ * */
109
+ isPageUpKey: ev => {
110
+ return ev.key === "PageUp";
111
+ },
112
+ /**
113
+ * Determines if the key pressed is the page down key
114
+ * */
115
+ isPageDownKey: ev => {
116
+ return ev.key === "PageDown";
117
+ },
106
118
  /**
107
119
  * Gets the event's path which is an array of the objects on which listeners will be invoked.
108
120
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath
@@ -1,6 +1,9 @@
1
1
  const setupScrollToMock = () => {
2
2
  // need to mock the `scrollTo` method, which is undefined in JSDOM. As we're not actually testing this behaviour, just make it
3
3
  // do nothing.
4
+ if (typeof window === "undefined") {
5
+ return;
6
+ }
4
7
  HTMLElement.prototype.scrollTo = () => {};
5
8
  };
6
9
  export default setupScrollToMock;
@@ -2,7 +2,7 @@ let mocked = false;
2
2
  let _matches = false;
3
3
  const removeEventListener = jest.fn();
4
4
  export const setupMatchMediaMock = () => {
5
- if (!global.window) {
5
+ if (typeof window === "undefined") {
6
6
  return;
7
7
  }
8
8
  const noop = () => {};
@@ -1,5 +1,5 @@
1
1
  const setupResizeObserverMock = () => {
2
- if (!window) {
2
+ if (typeof window === "undefined") {
3
3
  return;
4
4
  }
5
5
  window.ResizeObserver = window.ResizeObserver || jest.fn().mockImplementation(callback => {
@@ -1,5 +1,5 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- import React, { useState, useCallback, useMemo, useEffect, useRef, useImperativeHandle, forwardRef } from "react";
2
+ import React, { useState, useCallback, useMemo, useEffect, useRef, useImperativeHandle, forwardRef, useContext } from "react";
3
3
  import invariant from "invariant";
4
4
  import tagComponent from "../../__internal__/utils/helpers/tags";
5
5
  import { MenuButton, ButtonIcon, StyledButtonIcon } from "./action-popover.style";
@@ -13,6 +13,7 @@ import ActionPopoverDivider from "./action-popover-divider/action-popover-divide
13
13
  import ActionPopoverContext from "./__internal__/action-popover.context";
14
14
  import useModalManager from "../../hooks/__internal__/useModalManager";
15
15
  import { findFirstFocusableItem, findLastFocusableItem, getItems, checkChildrenForString } from "./__internal__/action-popover-utils";
16
+ import FlatTableContext from "../flat-table/__internal__/flat-table.context";
16
17
  const onOpenDefault = () => {};
17
18
  const onCloseDefault = () => {};
18
19
  export const ActionPopover = /*#__PURE__*/forwardRef(({
@@ -36,6 +37,9 @@ export const ActionPopover = /*#__PURE__*/forwardRef(({
36
37
  const [guid] = useState(createGuid());
37
38
  const buttonRef = useRef(null);
38
39
  const menu = useRef(null);
40
+ const {
41
+ isInFlatTable
42
+ } = useContext(FlatTableContext);
39
43
  const hasProperChildren = useMemo(() => {
40
44
  const incorrectChild = React.Children.toArray(children).find(child => {
41
45
  if (! /*#__PURE__*/React.isValidElement(child)) {
@@ -213,7 +217,8 @@ export const ActionPopover = /*#__PURE__*/forwardRef(({
213
217
  }
214
218
  }, isOpen && /*#__PURE__*/React.createElement(Popover, {
215
219
  placement: mappedPlacement,
216
- reference: buttonRef
220
+ reference: buttonRef,
221
+ disableBackgroundUI: isInFlatTable
217
222
  }, /*#__PURE__*/React.createElement(ActionPopoverMenu, _extends({
218
223
  "data-component": "action-popover",
219
224
  ref: menu
@@ -1,6 +1,6 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
2
  import { flip, offset } from "@floating-ui/dom";
3
- import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
+ import React, { useCallback, useEffect, useMemo, useRef, useState, useContext } from "react";
4
4
  import { DayPicker, defaultLocale } from "react-day-picker";
5
5
  import useLocale from "../../../../hooks/__internal__/useLocale";
6
6
  import Popover from "../../../../__internal__/popover";
@@ -9,6 +9,7 @@ import Weekday from "../weekday";
9
9
  import { getDisabledDays } from "../utils";
10
10
  import { defaultFocusableSelectors } from "../../../../__internal__/focus-trap/focus-trap-utils";
11
11
  import Events from "../../../../__internal__/utils/helpers/events";
12
+ import FlatTableContext from "../../../flat-table/__internal__/flat-table.context";
12
13
  import StyledDayPicker from "./day-picker.style";
13
14
  const popoverMiddleware = [offset(3), flip({
14
15
  fallbackStrategy: "initialPlacement"
@@ -100,6 +101,13 @@ export const DatePicker = ({
100
101
  }
101
102
  }, 0);
102
103
  };
104
+ const {
105
+ isInFlatTable,
106
+ setHasOpenDatePicker
107
+ } = useContext(FlatTableContext);
108
+ useEffect(() => {
109
+ setHasOpenDatePicker?.(!!open);
110
+ }, [open, setHasOpenDatePicker]);
103
111
  useEffect(() => {
104
112
  if (selectedDays) {
105
113
  setFocusedMonth(selectedDays);
@@ -122,7 +130,8 @@ export const DatePicker = ({
122
130
  placement: "bottom-start",
123
131
  reference: inputElement,
124
132
  middleware: popoverMiddleware,
125
- disablePortal: disablePortal
133
+ disablePortal: disablePortal,
134
+ disableBackgroundUI: isInFlatTable
126
135
  }, /*#__PURE__*/React.createElement(StyledDayPicker, {
127
136
  id: "styled-day-picker",
128
137
  "data-role": "date-picker",
@@ -1,7 +1,9 @@
1
- import React from "react";
1
+ import React, { Dispatch, SetStateAction } from "react";
2
2
  import { FlatTableProps } from "../flat-table.component";
3
3
  export interface FlatTableContextProps extends Pick<FlatTableProps, "colorTheme" | "size"> {
4
4
  getTabStopElementId: () => string;
5
+ isInFlatTable?: boolean;
6
+ setHasOpenDatePicker?: Dispatch<SetStateAction<boolean>>;
5
7
  }
6
8
  declare const _default: React.Context<FlatTableContextProps>;
7
9
  export default _default;
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
2
  export default /*#__PURE__*/React.createContext({
3
- getTabStopElementId: () => ""
3
+ getTabStopElementId: () => "",
4
+ isInFlatTable: false
4
5
  });
@@ -7,6 +7,7 @@ import StyledFlatTableHeader from "../flat-table-header/flat-table-header.style"
7
7
  import StyledIcon from "../../icon/icon.style";
8
8
  import { toColor } from "../../../style/utils/color";
9
9
  import addFocusStyling from "../../../style/utils/add-focus-styling";
10
+ import { getNavigator } from "../../../__internal__/dom/globals";
10
11
  import { isSafari } from "../../../__internal__/utils/helpers/browser-type-check";
11
12
  const horizontalBorderSizes = {
12
13
  medium: "2px",
@@ -101,6 +102,7 @@ const StyledFlatTableRow = styled.tr`
101
102
  draggable,
102
103
  rowHeight
103
104
  }) => {
105
+ const nav = getNavigator();
104
106
  const backgroundColor = bgColor ? toColor(theme, bgColor) : undefined;
105
107
  const customBorderColor = horizontalBorderColor ? toColor(theme, horizontalBorderColor) : undefined;
106
108
  const colorOfSelected = isInSidebar ? "var(--colorsUtilityMajor150)" : "var(--colorsUtilityMajor075)";
@@ -209,7 +211,8 @@ const StyledFlatTableRow = styled.tr`
209
211
  }
210
212
 
211
213
  /* Styling for safari. Position relative does not work on tr elements on Safari */
212
- ${isSafari(navigator) && css`
214
+ // FIXME: this can cause hydration mismatches during SSR.
215
+ ${nav && isSafari(nav) && css`
213
216
  position: -webkit-sticky;
214
217
  :after {
215
218
  border: none;
@@ -43,6 +43,7 @@ export const FlatTable = ({
43
43
  const {
44
44
  isInSidebar
45
45
  } = useContext(DrawerSidebarContext);
46
+ const [hasOpenDatePicker, setHasOpenDatePicker] = useState(false);
46
47
  useLayoutEffect(() => {
47
48
  const findRow = (rows, isFirstCol) => rows.find((row, index) => {
48
49
  const cells = Array.from(row.querySelectorAll("td, th"));
@@ -101,6 +102,12 @@ export const FlatTable = ({
101
102
  return;
102
103
  }
103
104
  const currentFocusIndex = focusableElementsArray.findIndex(el => el === document.activeElement);
105
+ if (hasOpenDatePicker && (hasStickyHead || hasStickyFooter)) {
106
+ if (Events.isPageUpKey(ev) || Events.isPageDownKey(ev) || Events.isHomeKey(ev) || Events.isEndKey(ev)) {
107
+ ev.preventDefault();
108
+ }
109
+ return;
110
+ }
104
111
  if (Events.isDownKey(ev)) {
105
112
  ev.preventDefault();
106
113
  if (currentFocusIndex !== -1 && currentFocusIndex < focusableElementsArray.length) {
@@ -183,7 +190,9 @@ export const FlatTable = ({
183
190
  value: {
184
191
  colorTheme,
185
192
  size,
186
- getTabStopElementId
193
+ getTabStopElementId,
194
+ isInFlatTable: true,
195
+ setHasOpenDatePicker
187
196
  }
188
197
  }, children))), footer && /*#__PURE__*/React.createElement(StyledFlatTableFooter, {
189
198
  hasStickyFooter: hasStickyFooter,
@@ -5,6 +5,7 @@ import baseTheme from "../../style/themes/base";
5
5
  import addFocusStyling from "../../style/utils/add-focus-styling";
6
6
  import styledColor from "../../style/utils/color";
7
7
  import getColorValue from "../../style/utils/get-color-value";
8
+ import { getNavigator, getWindow } from "../../__internal__/dom/globals";
8
9
  import browserTypeCheck, { isSafari } from "../../__internal__/utils/helpers/browser-type-check";
9
10
  import iconConfig from "./icon-config";
10
11
  import iconUnicodes from "./icon-unicodes";
@@ -48,6 +49,8 @@ const StyledIcon = styled.span`
48
49
  let finalHoverColor;
49
50
  let bgColor;
50
51
  let bgHoverColor;
52
+ const win = getWindow();
53
+ const nav = getNavigator();
51
54
  const adjustedBgSize = adjustIconBgSize(fontSize, bgSize);
52
55
  try {
53
56
  if (disabled) {
@@ -116,12 +119,11 @@ const StyledIcon = styled.span`
116
119
  font-size: ${iconConfig.iconSize[fontSize]};
117
120
  line-height: ${iconConfig.iconSize[fontSize]};
118
121
  `}
119
-
120
- ${type === "services" && browserTypeCheck(window) && css`
122
+ // FIXME: this can cause hydration mismatches during SSR.
123
+ ${win && type === "services" && browserTypeCheck(win) && css`
121
124
  margin-top: ${fontSize === "small" ? "-7px" : "-8px"};
122
125
  `}
123
-
124
- ${type === "services" && isSafari(navigator) && !browserTypeCheck(window) && css`
126
+ ${nav && win && type === "services" && isSafari(nav) && !browserTypeCheck(win) && css`
125
127
  margin-top: -6px;
126
128
  `}
127
129
 
@@ -10,6 +10,7 @@ import Icon from "../../icon";
10
10
  import Portal from "../../portal";
11
11
  import FocusTrap from "../../../__internal__/focus-trap";
12
12
  import MenuDivider from "../menu-divider/menu-divider.component";
13
+ import { getDocument } from "../../../__internal__/dom/globals";
13
14
  import useLocale from "../../../hooks/__internal__/useLocale";
14
15
  import useModalAria from "../../../hooks/__internal__/useModalAria";
15
16
  import useModalManager from "../../../hooks/__internal__/useModalManager";
@@ -54,7 +55,7 @@ export const MenuFullscreen = ({
54
55
  closeModal,
55
56
  modalRef: menuRef,
56
57
  topModalOverride,
57
- focusCallToActionElement: document.activeElement
58
+ focusCallToActionElement: getDocument()?.activeElement
58
59
  });
59
60
  return /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(CSSTransition, {
60
61
  nodeRef: menuRef,
@@ -4,6 +4,7 @@ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r),
4
4
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
6
6
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ import { getWindow } from "../../../__internal__/dom/globals";
7
8
  let ModalManagerInstance = /*#__PURE__*/function () {
8
9
  function ModalManagerInstance() {
9
10
  _classCallCheck(this, ModalManagerInstance);
@@ -27,12 +28,17 @@ let ModalManagerInstance = /*#__PURE__*/function () {
27
28
  });
28
29
  this.callTopModalSetters();
29
30
  });
31
+ const safeWindow = getWindow();
32
+ if (!safeWindow) {
33
+ this.modalList = [];
34
+ return;
35
+ }
30
36
  // Due to possibility of multiple carbon versions using it
31
37
  // it is necessary to maintain same structure in this global variable
32
- if (!window.__CARBON_INTERNALS_MODAL_LIST) {
33
- window.__CARBON_INTERNALS_MODAL_LIST = [];
38
+ if (!safeWindow.__CARBON_INTERNALS_MODAL_LIST) {
39
+ safeWindow.__CARBON_INTERNALS_MODAL_LIST = [];
34
40
  }
35
- this.modalList = window.__CARBON_INTERNALS_MODAL_LIST;
41
+ this.modalList = safeWindow.__CARBON_INTERNALS_MODAL_LIST;
36
42
  }
37
43
  return _createClass(ModalManagerInstance, [{
38
44
  key: "getTopModal",
@@ -78,16 +84,21 @@ let ModalManagerInstance = /*#__PURE__*/function () {
78
84
  }, {
79
85
  key: "clearList",
80
86
  value: function clearList() {
81
- window.__CARBON_INTERNALS_MODAL_LIST = [];
82
- this.modalList = window.__CARBON_INTERNALS_MODAL_LIST;
87
+ const safeWindow = getWindow();
88
+ const cleared = [];
89
+ if (safeWindow) {
90
+ safeWindow.__CARBON_INTERNALS_MODAL_LIST = cleared;
91
+ }
92
+ this.modalList = cleared;
83
93
  this.callTopModalSetters();
84
94
  }
85
95
  }, {
86
96
  key: "callTopModalSetters",
87
97
  value: function callTopModalSetters() {
88
- if (window.__CARBON_INTERNALS_MODAL_SETTER_LIST) {
98
+ const safeWindow = getWindow();
99
+ if (safeWindow?.__CARBON_INTERNALS_MODAL_SETTER_LIST) {
89
100
  const topModal = this.getTopModal()?.modal || null;
90
- for (const setTopModal of window.__CARBON_INTERNALS_MODAL_SETTER_LIST) {
101
+ for (const setTopModal of safeWindow.__CARBON_INTERNALS_MODAL_SETTER_LIST) {
91
102
  setTopModal(topModal);
92
103
  }
93
104
  }
@@ -3,6 +3,7 @@ import React, { useEffect, useRef, useCallback, useState } from "react";
3
3
  import { TransitionGroup, CSSTransition } from "react-transition-group";
4
4
  import useScrollBlock from "../../hooks/__internal__/useScrollBlock";
5
5
  import Portal from "../portal";
6
+ import { getDocument } from "../../__internal__/dom/globals";
6
7
  import Events from "../../__internal__/utils/helpers/events";
7
8
  import useModalManager from "../../hooks/__internal__/useModalManager";
8
9
  import { StyledModal, StyledModalBackground } from "./modal.style";
@@ -53,13 +54,14 @@ const Modal = ({
53
54
  onCancel(ev);
54
55
  }
55
56
  }, [disableClose, disableEscKey, onCancel]);
57
+ const safeDocument = getDocument();
56
58
  useModalManager({
57
59
  open,
58
60
  closeModal,
59
61
  modalRef: ref,
60
62
  setTriggerRefocusFlag,
61
63
  topModalOverride,
62
- focusCallToActionElement: restoreFocusOnClose ? document.activeElement : undefined
64
+ focusCallToActionElement: restoreFocusOnClose && safeDocument ? safeDocument.activeElement : undefined
63
65
  });
64
66
  let background;
65
67
  let content;
@@ -1,5 +1,5 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- import React, { useRef, forwardRef, useImperativeHandle } from "react";
2
+ import React, { useRef, forwardRef, useImperativeHandle, useContext } from "react";
3
3
  import { flip, offset } from "@floating-ui/dom";
4
4
  import useClickAwayListener from "../../hooks/__internal__/useClickAwayListener";
5
5
  import SplitButtonContext from "../split-button/__internal__/split-button.context";
@@ -8,6 +8,7 @@ import Button from "../button";
8
8
  import Popover from "../../__internal__/popover";
9
9
  import { filterStyledSystemMarginProps, filterOutStyledSystemSpacingProps } from "../../style/utils";
10
10
  import useChildButtons from "../../hooks/__internal__/useChildButtons";
11
+ import FlatTableContext from "../flat-table/__internal__/flat-table.context";
11
12
  export const MultiActionButton = /*#__PURE__*/forwardRef(({
12
13
  align = "left",
13
14
  position = "left",
@@ -24,6 +25,9 @@ export const MultiActionButton = /*#__PURE__*/forwardRef(({
24
25
  ...rest
25
26
  }, ref) => {
26
27
  const buttonRef = useRef(null);
28
+ const {
29
+ isInFlatTable
30
+ } = useContext(FlatTableContext);
27
31
  useImperativeHandle(ref, () => ({
28
32
  focusMainButton() {
29
33
  buttonRef.current?.focus();
@@ -58,6 +62,7 @@ export const MultiActionButton = /*#__PURE__*/forwardRef(({
58
62
  ...filterOutStyledSystemSpacingProps(rest)
59
63
  };
60
64
  const renderAdditionalButtons = () => /*#__PURE__*/React.createElement(Popover, {
65
+ disableBackgroundUI: isInFlatTable,
61
66
  disablePortal: true,
62
67
  placement: position === "left" ? "bottom-start" : /* istanbul ignore next */"bottom-end",
63
68
  reference: buttonNode,
@@ -1,5 +1,5 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
- import React, { useCallback, useEffect, useRef, useState, useMemo, useImperativeHandle, forwardRef } from "react";
2
+ import React, { useCallback, useEffect, useRef, useState, useMemo, useImperativeHandle, forwardRef, useContext } from "react";
3
3
  import { CSSTransition } from "react-transition-group";
4
4
  import { flip, offset } from "@floating-ui/dom";
5
5
  import useMediaQuery from "../../hooks/useMediaQuery";
@@ -15,6 +15,7 @@ import ModalContext from "../modal/__internal__/modal.context";
15
15
  import useFocusPortalContent from "../../hooks/__internal__/useFocusPortalContent";
16
16
  import tagComponent from "../../__internal__/utils/helpers/tags/tags";
17
17
  import { defaultFocusableSelectors } from "../../__internal__/focus-trap/focus-trap-utils";
18
+ import FlatTableContext from "../flat-table/__internal__/flat-table.context";
18
19
  export const renderOpen = ({
19
20
  tabIndex,
20
21
  onClick,
@@ -95,6 +96,9 @@ export const PopoverContainer = /*#__PURE__*/forwardRef(({
95
96
  const isOpen = isControlled ? open : isOpenInternal;
96
97
  const reduceMotion = !useMediaQuery("screen and (prefers-reduced-motion: no-preference)");
97
98
  const popoverMiddleware = usePopoverMiddleware(shouldCoverButton);
99
+ const {
100
+ isInFlatTable
101
+ } = useContext(FlatTableContext);
98
102
  const closePopover = useCallback(ev => {
99
103
  /* istanbul ignore else */
100
104
  if (!isControlled) setIsOpenInternal(false);
@@ -238,7 +242,8 @@ export const PopoverContainer = /*#__PURE__*/forwardRef(({
238
242
  placement: position === "right" ? "bottom-start" : "bottom-end",
239
243
  popoverStrategy: disableAnimation || reduceMotion ? "fixed" : "absolute",
240
244
  middleware: popoverMiddleware,
241
- childRefOverride: popoverContentNodeRef
245
+ childRefOverride: popoverContentNodeRef,
246
+ disableBackgroundUI: isInFlatTable
242
247
  }, childrenToRender())));
243
248
  });
244
249
  export default PopoverContainer;
@@ -15,6 +15,7 @@ import { baseTheme } from "../../style/themes";
15
15
  import useChildButtons from "../../hooks/__internal__/useChildButtons";
16
16
  import SplitButtonContext from "./__internal__/split-button.context";
17
17
  import useLocale from "../../hooks/__internal__/useLocale";
18
+ import FlatTableContext from "../flat-table/__internal__/flat-table.context";
18
19
  const CONTENT_WIDTH_RATIO = 0.75;
19
20
  export const SplitButton = /*#__PURE__*/forwardRef(({
20
21
  align = "left",
@@ -38,6 +39,9 @@ export const SplitButton = /*#__PURE__*/forwardRef(({
38
39
  const buttonLabelId = useRef(guid());
39
40
  const mainButtonRef = useRef(null);
40
41
  const toggleButtonRef = useRef(null);
42
+ const {
43
+ isInFlatTable
44
+ } = useContext(FlatTableContext);
41
45
  useImperativeHandle(ref, () => ({
42
46
  focusMainButton() {
43
47
  mainButtonRef.current?.focus();
@@ -124,6 +128,7 @@ export const SplitButton = /*#__PURE__*/forwardRef(({
124
128
  function renderAdditionalButtons() {
125
129
  if (!showAdditionalButtons) return null;
126
130
  return /*#__PURE__*/React.createElement(Popover, {
131
+ disableBackgroundUI: isInFlatTable,
127
132
  disablePortal: true,
128
133
  placement: position === "left" ? /* istanbul ignore next */"bottom-start" : "bottom-end",
129
134
  popoverStrategy: "fixed",
@@ -9,6 +9,7 @@ import Icon from "../../icon";
9
9
  import Box from "../../box";
10
10
  import { StyledList, StyledVerticalMenuFullScreen } from "../vertical-menu.style";
11
11
  import VerticalMenuFullScreenContext from "./__internal__/vertical-menu-full-screen.context";
12
+ import { getDocument } from "../../../__internal__/dom/globals";
12
13
  import Events from "../../../__internal__/utils/helpers/events/events";
13
14
  import useModalManager from "../../../hooks/__internal__/useModalManager";
14
15
  export const VerticalMenuFullScreen = ({
@@ -27,12 +28,13 @@ export const VerticalMenuFullScreen = ({
27
28
  onClose(ev);
28
29
  }
29
30
  }, [onClose]);
31
+ const safeDocument = getDocument();
30
32
  useModalManager({
31
33
  open: isOpen,
32
34
  closeModal: handleKeyDown,
33
35
  modalRef: menuWrapperRef,
34
36
  topModalOverride: true,
35
- focusCallToActionElement: document.activeElement
37
+ focusCallToActionElement: safeDocument?.activeElement
36
38
  });
37
39
 
38
40
  // TODO remove this as part of FE-5650
@@ -6,24 +6,31 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
6
6
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
7
  // TODO: This component can be refactored to remove redundant code
8
8
  // once we can confirm that all Sage products use version 105.0.0^
9
+ import { getWindow } from "../../../__internal__/dom/globals";
9
10
  let ScrollBlockManager = /*#__PURE__*/function () {
10
11
  function ScrollBlockManager() {
11
12
  _classCallCheck(this, ScrollBlockManager);
12
13
  _defineProperty(this, "components", void 0);
13
14
  _defineProperty(this, "originalValues", void 0);
15
+ const safeWindow = getWindow();
16
+ if (!safeWindow) {
17
+ this.components = {};
18
+ this.originalValues = [];
19
+ return;
20
+ }
14
21
  // Due to possibility of multiple carbon versions using it
15
22
  // it is necessary to maintain same structure in this global variable
16
- if (!window.__CARBON_INTERNALS_SCROLL_BLOCKERS) {
17
- window.__CARBON_INTERNALS_SCROLL_BLOCKERS = {
23
+ if (!safeWindow.__CARBON_INTERNALS_SCROLL_BLOCKERS) {
24
+ safeWindow.__CARBON_INTERNALS_SCROLL_BLOCKERS = {
18
25
  components: {},
19
26
  // originalValues can be removed
20
27
  originalValues: [],
21
28
  restoreValues: null
22
29
  };
23
30
  }
24
- this.components = window.__CARBON_INTERNALS_SCROLL_BLOCKERS.components;
31
+ this.components = safeWindow.__CARBON_INTERNALS_SCROLL_BLOCKERS.components;
25
32
  // TODO: originalValues can be removed
26
- this.originalValues = window.__CARBON_INTERNALS_SCROLL_BLOCKERS.originalValues;
33
+ this.originalValues = safeWindow.__CARBON_INTERNALS_SCROLL_BLOCKERS.originalValues;
27
34
  }
28
35
  return _createClass(ScrollBlockManager, [{
29
36
  key: "registerComponent",