@synerise/ds-modal 1.6.9 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.7.1](https://github.com/synerise/synerise-design/compare/@synerise/ds-modal@1.7.0...@synerise/ds-modal@1.7.1) (2026-08-20)
7
+
8
+ ### Bug Fixes
9
+
10
+ - stack nested modals above their enclosing overlay ([c7f75c0](https://github.com/synerise/synerise-design/commit/c7f75c0fb39dc29e23997364640a2733811e4b51))
11
+
12
+ # [1.7.0](https://github.com/synerise/synerise-design/compare/@synerise/ds-modal@1.6.9...@synerise/ds-modal@1.7.0) (2026-08-18)
13
+
14
+ ### Features
15
+
16
+ - **modal:** close open modals via closeAllOverlays ([208e41c](https://github.com/synerise/synerise-design/commit/208e41c7e0b2e905b170f98ec58d302a86c04932))
17
+
6
18
  ## [1.6.9](https://github.com/synerise/synerise-design/compare/@synerise/ds-modal@1.6.8...@synerise/ds-modal@1.6.9) (2026-08-14)
7
19
 
8
20
  **Note:** Version bump only for package @synerise/ds-modal
package/CLAUDE.md CHANGED
@@ -75,7 +75,7 @@ src/
75
75
  | `closeButtonAriaLabel` | `string` | `DS.MODAL.CLOSE` (`'Close'`) | Accessible name for the close button; defaults to the localised translation |
76
76
  | `initialFocusRef` | `RefObject<HTMLElement \| null>` | dialog container | Element focused on open. Defaults to the dialog container (announced by its accessible name). Pass a ref only when focusing a specific control is genuinely useful (search/rename dialogs) |
77
77
  | `getContainer` | `() => HTMLElement` | `document.body` | Portal mount target |
78
- | `zIndex` | `number` | theme `zindex-modal` | z-index of the modal root |
78
+ | `zIndex` | `number` | derived, see below | z-index of the modal root. Omit it and the modal stacks `OVERLAY_Z_INDEX_STEP` (2) above the nearest enclosing modal/drawer, falling back to the `zindex-modal` token when nothing encloses it. Set it to opt out of the stack entirely |
79
79
 
80
80
  ### `showModal(props: ModalProps): ModalHandle`
81
81
 
@@ -171,6 +171,7 @@ document.body (portal target)
171
171
  - **`fullScreen`** positions the modal `fixed` covering the viewport; body scrolls via `overflow: scroll`.
172
172
  - **`maxViewportHeight`** anchors the modal to the bottom of the viewport (sheet-style), not the centre.
173
173
  - **Async handlers:** Both `onOk` and `onCancel` can return `Promise`. `onCancel` awaits the promise then calls `closeModal()`. `onOk` resolves then calls `closeModal()` only if the handler was detected as promise-returning via `'then' in onOk`.
174
+ - **Nested-modal stacking:** `ModalContent` resolves its z-index through `useResolvedOverlayZIndex` from `@synerise/ds-core` and re-publishes the result to its whole subtree via `OverlayZIndexProvider`, so a modal opened from inside another modal renders above it without either side coordinating. This cannot be left to DOM order: every modal portals to `document.body` and React commits the **innermost** portal first, so a nested modal ends up *before* its parent in the document. The provider wraps `ModalRoot` rather than just `children`, so a modal passed through `prefix` / `footer` / `headerActions` stacks too. An explicit `zIndex` always wins and is not clamped; derived values are clamped just below `zindex-dropdown` so a modal can never cover a dropdown, select, popconfirm or tooltip opened inside it. `showModal()` renders at `DSProvider` level, outside any modal's React subtree, so it never derives — pass `zIndex` there if it must stack. See "Overlay z-index" in `@synerise/ds-core`'s CLAUDE.md.
174
175
  - **Accessibility:** `ModalContainer` carries `role="dialog"` + `aria-modal`. `ModalContent` generates two ids with React's `useId()` — `titleId` and `descriptionId` — passed to `ModalTitle` which applies them to `S.Title` (the `<h3>`) and `S.Description`. The dialog references them via `aria-labelledby` (when `title` is set) and `aria-describedby` (when `description` is set); `aria-label` falls back to the `ariaLabel` prop when there is no title. Both close buttons (header and `blank`) get `aria-label` from `closeButtonAriaLabel`, falling back to the localised `DS.MODAL.CLOSE` message (`useIntl().formatMessage`, default `'Close'`); `react-intl` is a peer dependency. Focus trap/restore is handled by `useFocusTrap`; `Escape` closes via `handleKeyDown`. **Initial focus:** on open, focus moves to the `ModalContainer` (`role="dialog"`, `tabIndex={-1}`) itself — screen readers announce the dialog's accessible name + role and no cursor lands in a non-critical field. This satisfies the WAI-ARIA APG Dialog pattern (focus must move *into* the dialog, but not necessarily onto the first focusable element). Consumers can override the target with `initialFocusRef` (e.g. focus a search field); it is passed straight to `useFocusTrap`'s `initialFocus` option.
175
176
 
176
177
  ## Key dependencies
package/README.md CHANGED
@@ -205,3 +205,14 @@ The following prop is **deprecated** and will be removed in a future major versi
205
205
  | Prop | Replacement |
206
206
  | ---- | ----------- |
207
207
  | `description` | `headerBottomBar` |
208
+
209
+ ## Closing programmatically
210
+
211
+ `closeAllOverlays()` from `@synerise/ds-core` force-closes every open DS overlay in one call — useful when an app-level event (e.g. the active workspace changed in another tab) invalidates whatever the user is doing. This component closes through its own close path, so its handlers fire and focus is restored.
212
+
213
+ ```ts
214
+ import { closeAllOverlays } from '@synerise/ds-core';
215
+
216
+ await closeAllOverlays();
217
+ await closeAllOverlays({ kinds: ['modal', 'drawer'] }); // leave tooltips alone
218
+ ```
@@ -1,6 +1,7 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- import { forwardRef, useRef, useId, useMemo, useCallback, useImperativeHandle } from "react";
3
- import { useFocusTrap } from "@synerise/ds-utils";
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useRef, useId, useMemo, useCallback, useImperativeHandle, useEffect } from "react";
3
+ import { useResolvedOverlayZIndex, registerOverlay, createOverlayCloseEvent, OverlayZIndexProvider } from "@synerise/ds-core";
4
+ import { useLatestRef, useFocusTrap } from "@synerise/ds-utils";
4
5
  import { SIZE_MAP } from "../../Modal.const.js";
5
6
  import { ModalFooter } from "../ModalFooter/ModalFooter.js";
6
7
  import { ModalTitle } from "../ModalTitle/ModalTitle.js";
@@ -44,9 +45,11 @@ const ModalContent = forwardRef(({
44
45
  ariaLabel,
45
46
  closeButtonAriaLabel,
46
47
  initialFocusRef,
48
+ zIndex,
47
49
  ...rest
48
50
  }, modalRef) => {
49
51
  const scrollRef = useRef(null);
52
+ const resolvedZIndex = useResolvedOverlayZIndex(zIndex);
50
53
  const titleId = useId();
51
54
  const descriptionId = useId();
52
55
  const DEFAULT_VIEWPORT_HEIGHT = 80;
@@ -103,10 +106,20 @@ const ModalContent = forwardRef(({
103
106
  };
104
107
  const containerRef = useRef(null);
105
108
  const dialogRef = useRef(null);
109
+ const handleCancelRef = useLatestRef(handleCancel);
110
+ useEffect(() => {
111
+ if (hidden) {
112
+ return void 0;
113
+ }
114
+ return registerOverlay({
115
+ kind: "modal",
116
+ close: () => handleCancelRef.current(createOverlayCloseEvent(containerRef.current))
117
+ });
118
+ }, [hidden, handleCancelRef]);
106
119
  useFocusTrap(containerRef, !hidden, {
107
120
  initialFocus: initialFocusRef ?? dialogRef
108
121
  });
109
- return /* @__PURE__ */ jsxs(ModalRoot, { "data-testid": "ds-modal", ...rest, $hidden: hidden, "data-visible": !hidden, onKeyDown: handleKeyDown, tabIndex: -1, ref: containerRef, children: [
122
+ return /* @__PURE__ */ jsx(OverlayZIndexProvider, { value: resolvedZIndex, children: /* @__PURE__ */ jsxs(ModalRoot, { "data-testid": "ds-modal", ...rest, zIndex: resolvedZIndex, $hidden: hidden, "data-visible": !hidden, onKeyDown: handleKeyDown, tabIndex: -1, ref: containerRef, children: [
110
123
  /* @__PURE__ */ jsx(ModalMask, {}),
111
124
  /* @__PURE__ */ jsx(ModalScrollWrap, { ref: scrollRef, onClick: handleMaskClick, children: /* @__PURE__ */ jsxs(ModalContainer, { ref: dialogRef, tabIndex: -1, onClick: cancelClick, role: "dialog", "aria-modal": true, "aria-labelledby": title ? titleId : void 0, "aria-label": !title ? ariaLabel : void 0, "aria-describedby": description ? descriptionId : void 0, isFullscreen, $width: size && SIZE_MAP[size], maxHeight, centered, children: [
112
125
  /* @__PURE__ */ jsx(ModalTitle, { headerActions, blank, titleContainerStyle, onCancel: closable && onCancel ? handleCancel : void 0, title, titleId, description, descriptionId, headerTabProps, headerBottomBar, closeButtonAriaLabel }),
@@ -115,7 +128,7 @@ const ModalContent = forwardRef(({
115
128
  }, absolute: true, classes: "ds-modal-body-scrollbar", ref: bodyScrollRef, children }) }) : children }),
116
129
  /* @__PURE__ */ jsx(ModalFooter, { CustomFooterButton, prefix, infix, suffix, onOk: onOk ? handleOk : void 0, onCancel: onCancel ? handleCancel : void 0, texts, okButton, okButtonProps, cancelButton, cancelButtonProps, cancelText, okText, okType, footer })
117
130
  ] }) })
118
- ] });
131
+ ] }) });
119
132
  });
120
133
  export {
121
134
  ModalContent
package/dist/Modal.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { forwardRef, useState, useRef, useEffect } from "react";
3
3
  import { createPortal } from "react-dom";
4
+ import { useLatestRef } from "@synerise/ds-utils";
4
5
  import { ModalContent } from "./Elements/ModalContent/ModalContent.js";
5
6
  const Modal = forwardRef(({
6
7
  open,
@@ -12,19 +13,20 @@ const Modal = forwardRef(({
12
13
  const [isOpen, setIsOpen] = useState(open);
13
14
  const [hasBeenOpened, setHasBeenOpened] = useState(open);
14
15
  const prevOpenRef = useRef(open);
16
+ const afterCloseRef = useLatestRef(afterClose);
15
17
  useEffect(() => {
16
18
  setIsOpen(open);
17
19
  if (open) {
18
20
  setHasBeenOpened(true);
19
21
  } else if (prevOpenRef.current) {
20
- afterClose?.();
22
+ afterCloseRef.current?.();
21
23
  }
22
24
  prevOpenRef.current = open;
23
- }, [open, afterClose]);
25
+ }, [open, afterCloseRef]);
24
26
  const closeModal = () => {
25
27
  setIsOpen((prev) => {
26
28
  if (prev) {
27
- afterClose?.();
29
+ afterCloseRef.current?.();
28
30
  }
29
31
  return false;
30
32
  });
@@ -176,8 +176,10 @@ export type ModalProps = {
176
176
  /** Inline styles applied to the modal body element. */
177
177
  bodyStyle?: CSSProperties;
178
178
  /**
179
- * `z-index` of the modal root.
180
- * @defaultValue theme `zindex-modal`
179
+ * `z-index` of the modal root. Omit it and the modal stacks one step above
180
+ * the nearest enclosing modal/drawer, falling back to the `zindex-modal`
181
+ * token when nothing encloses it. Set it to opt out of that stack.
182
+ * @defaultValue derived from the enclosing overlay, else theme `zindex-modal`
181
183
  */
182
184
  zIndex?: number;
183
185
  /** CSS class applied to the modal root. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-modal",
3
- "version": "1.6.9",
3
+ "version": "1.7.1",
4
4
  "description": "Modal UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "synerise/synerise-design",
@@ -39,14 +39,16 @@
39
39
  "sideEffects": false,
40
40
  "types": "dist/index.d.ts",
41
41
  "dependencies": {
42
- "@synerise/ds-button": "^1.5.36",
42
+ "@synerise/ds-button": "^1.5.37",
43
43
  "@synerise/ds-icon": "^1.18.5",
44
44
  "@synerise/ds-scrollbar": "^1.5.2",
45
- "@synerise/ds-tabs": "^1.2.9",
46
- "@synerise/ds-typography": "^1.1.28",
45
+ "@synerise/ds-tabs": "^1.2.10",
46
+ "@synerise/ds-typography": "^1.1.29",
47
47
  "@synerise/ds-utils": "^1.10.2"
48
48
  },
49
49
  "devDependencies": {
50
+ "@synerise/ds-dropdown": "^1.4.0",
51
+ "@synerise/ds-popconfirm": "^1.5.0",
50
52
  "vitest": "4"
51
53
  },
52
54
  "peerDependencies": {
@@ -55,5 +57,5 @@
55
57
  "react-intl": ">=3.12.0 <= 6.8",
56
58
  "styled-components": "^5.3.3"
57
59
  },
58
- "gitHead": "fbaec1b62812804ecab17db27553c2071c7bad49"
60
+ "gitHead": "8d271661b4af7b8580871b750e0be1a8fe1844b2"
59
61
  }