@synerise/ds-modal 2.2.0 → 2.2.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
+ ## [2.2.1](https://github.com/synerise/synerise-design/compare/@synerise/ds-modal@2.2.0...@synerise/ds-modal@2.2.1) (2026-11-03)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * leave a modal's close to its consumer when onCancel is set ([b8bc321](https://github.com/synerise/synerise-design/commit/b8bc32192ce6afd90c79464886fd8ffa31adf558))
12
+ * **modal:** reserve the scrollbar gutter so stacked modals line up ([2b8ac3c](https://github.com/synerise/synerise-design/commit/2b8ac3cb85b0e2b7deaac4ae3868c3b5b60567b1))
13
+
14
+
15
+
16
+
17
+
6
18
  # [2.2.0](https://github.com/synerise/synerise-design/compare/@synerise/ds-modal@2.1.1...@synerise/ds-modal@2.2.0) (2026-10-29)
7
19
 
8
20
 
package/CLAUDE.md CHANGED
@@ -39,14 +39,14 @@ src/
39
39
 
40
40
  | Prop | Type | Default | Description |
41
41
  |------|------|---------|-------------|
42
- | `open` | `boolean` | `false` | Whether the modal is visible |
42
+ | `open` | `boolean` | `false` | Whether the modal is visible, and the only thing that hides it. Cancel gestures call `onCancel` and leave this prop alone |
43
43
  | `destroyOnClose` | `boolean` | `false` | When true, unmounts children on close. When false, keeps mounted but hidden |
44
44
  | `title` | `ReactNode` | — | Modal header title |
45
45
  | `size` | `ModalSize` | — | Predefined width: `small` (520px), `medium` (792px), `large` (1044px), `extraLarge` (1280px), `fullSize` (100%), `fullScreen` (fixed, 24px gutter on every side) |
46
46
  | `bodyBackground` | `'white' \| 'grey'` | `'white'` | Background colour of the modal body |
47
47
  | `blank` | `boolean` | — | Strips header/footer chrome; shows only a close button if `onCancel` is provided |
48
48
  | `closable` | `boolean` | `true` | Whether the close button is shown (gated in ModalContent before reaching ModalTitle) |
49
- | `maskClosable` | `boolean` | `true` | Whether clicking the backdrop closes the modal |
49
+ | `maskClosable` | `boolean` | `true` | Whether clicking the backdrop requests a close |
50
50
  | `centered` | `boolean` | `false` | Vertically centres the modal |
51
51
  | `maxViewportHeight` | `true \| number` | — | Caps height. `true` → 80vh; number → Nvh. Wraps children in scrollbar. Anchors modal to bottom of viewport |
52
52
  | `disableScrollbar` | `boolean` | — | Disables scrollbar wrapping from `maxViewportHeight` |
@@ -57,7 +57,7 @@ src/
57
57
  | `titleContainerStyle` | `CSSProperties` | — | Inline styles for the title container |
58
58
  | `description` | `ReactNode` | — | **Deprecated.** Sub-title with dashed separator |
59
59
  | `onOk` | `(e) => void \| Promise` | — | OK button handler; async supported — modal stays open until resolved |
60
- | `onCancel` | `(e) => void \| Promise` | — | Cancel/close handler; async supported |
60
+ | `onCancel` | `(e) => void \| Promise` | — | Cancel/close handler; async supported. It is a close request: the modal hides only when `open` is lowered. With no `onCancel` the modal closes itself |
61
61
  | `afterClose` | `() => void` | — | Called after each close (every `open: true → false` transition). Matches antd Modal semantics. Does not fire on initial mount or on hard unmount of an open modal. |
62
62
  | `footer` | `ReactNode \| null` | auto-generated | `null` suppresses footer; custom ReactNode overrides it |
63
63
  | `texts` | `{ okButton?; cancelButton? }` | `{ okButton: 'Apply', cancelButton: 'Cancel' }` | Default button labels |
@@ -156,7 +156,7 @@ DOM structure when visible:
156
156
  document.body (portal target)
157
157
  └─ ModalRoot (position: absolute, z-index from theme)
158
158
  ├─ ModalMask (position: fixed, full viewport, semi-transparent)
159
- └─ ModalScrollWrap (position: fixed, full viewport, overflow: auto)
159
+ └─ ModalScrollWrap (position: fixed, full viewport, overflow: auto, scrollbar-gutter: stable)
160
160
  └─ ModalContainer (absolute or fixed, sized, centered)
161
161
  ├─ ModalTitle (header: title, tabs, actions, close button)
162
162
  ├─ ModalBody (content, optional grey background)
@@ -169,6 +169,7 @@ document.body (portal target)
169
169
  - **Title render condition:** Header renders when at least one of `title`, `description`, `headerTabProps` is truthy. `headerBottomBar` renders independently.
170
170
  - **Footer render logic:** `footer={null}` suppresses entirely. Explicit `footer` value overrides auto-generated `ModalFooter`. Omitted `footer` renders the default.
171
171
  - **`fullScreen`** positions the modal `fixed`, inset 24px from every viewport edge so the mask shows around it; body scrolls via `overflow: scroll`.
172
+ - **Scrollbar gutter:** every modal has its own `ModalScrollWrap`, and `ModalContainer` centres on `left: 50%` of it. A classic scrollbar on a modal taller than the viewport would narrow only that wrap and move its box half a scrollbar left of a shorter modal stacked over it, so the wrap always reserves the gutter (`scrollbar-gutter: stable`). Story `AlignsStackedModalsOfDifferentHeights` covers it.
172
173
  - **`maxViewportHeight`** anchors the modal to the bottom of the viewport (sheet-style), not the centre.
173
174
  - **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
175
  - **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.
package/README.md CHANGED
@@ -32,6 +32,29 @@ import Modal from '@synerise/ds-modal';
32
32
  </Modal>
33
33
  ```
34
34
 
35
+ ### Who closes the modal
36
+
37
+ `open` is the only thing that hides the modal. The close button, `Escape`, the backdrop and
38
+ `closeAllOverlays` call `onCancel` and leave `open` alone, so the modal stays up until you
39
+ lower it yourself. That lets a handler refuse the close — to raise an unsaved-changes prompt,
40
+ say:
41
+
42
+ ```tsx
43
+ <Modal
44
+ open={isOpen}
45
+ onCancel={() => {
46
+ if (hasUnsavedChanges) {
47
+ setPromptVisible(true);
48
+ return;
49
+ }
50
+ setIsOpen(false);
51
+ }}
52
+ />
53
+ ```
54
+
55
+ Without an `onCancel` there is nobody to ask, so the modal closes itself on those same
56
+ gestures. `showModal` holds `open` for you and lowers it once your `onCancel` resolves.
57
+
35
58
  ### Imperative API
36
59
 
37
60
  Use `showModal` when you need to open a modal outside of the React component tree:
@@ -97,9 +120,9 @@ ref.current?.scrollToBottom();
97
120
  | `blank` | Renders a minimal modal without any header/footer chrome; only a close button is shown when `onCancel` is set | `boolean` | `false` |
98
121
  | `centered` | Vertically centers the modal in the viewport | `boolean` | `false` |
99
122
  | `closable` | Whether the close (×) button is shown | `boolean` | `true` |
100
- | `maskClosable` | Whether clicking the backdrop closes the modal | `boolean` | `true` |
123
+ | `maskClosable` | Whether clicking the backdrop requests a close | `boolean` | `true` |
101
124
  | `onOk` | Called when the OK / Apply button is clicked; may return a `Promise` — modal stays open until it resolves | `(e: MouseEvent) => void \| Promise<unknown>` | – |
102
- | `onCancel` | Called when the close button, backdrop, or Cancel button is clicked; may return a `Promise` | `(e: MouseEvent) => void \| Promise<unknown>` | – |
125
+ | `onCancel` | Called when the close button, backdrop, or Cancel button is clicked; may return a `Promise`. It is a close request — lower `open` to close | `(e: MouseEvent) => void \| Promise<unknown>` | – |
103
126
  | `afterClose` | Called after the modal has fully unmounted | `() => void` | – |
104
127
  | `footer` | Custom footer content. Set `footer={null}` to remove the footer entirely | `ReactNode` | OK + Cancel buttons |
105
128
  | `okText` | Label for the OK button | `ReactNode` | `Apply` |
@@ -1,6 +1,6 @@
1
1
  import { default as React } from 'react';
2
2
  import { ModalRef } from '../../Modal.types';
3
- export declare const ModalContent: React.ForwardRefExoticComponent<Omit<import('../../Modal.types').ModalProps, "getContainer" | "open" | "destroyOnClose" | "afterClose"> & {
3
+ export declare const ModalContent: React.ForwardRefExoticComponent<Omit<import('../..').ModalProps, "getContainer" | "open" | "destroyOnClose" | "afterClose"> & {
4
4
  closeModal: () => void;
5
5
  hidden?: boolean;
6
6
  } & React.RefAttributes<ModalRef>>;
@@ -1,5 +1,5 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useRef, useId, useMemo, useCallback, useImperativeHandle, useEffect } from "react";
2
+ import { forwardRef, useRef, useState, useId, useMemo, useCallback, useImperativeHandle, useEffect } from "react";
3
3
  import { useResolvedOverlayZIndex, registerOverlay, createOverlayCloseEvent, OverlayZIndexProvider } from "@synerise/ds-core";
4
4
  import { useLatestRef, useFocusTrap } from "@synerise/ds-utils";
5
5
  import { SIZE_MAP } from "../../Modal.const.js";
@@ -49,6 +49,7 @@ const ModalContent = forwardRef(({
49
49
  ...rest
50
50
  }, modalRef) => {
51
51
  const scrollRef = useRef(null);
52
+ const [cancelAttempts, setCancelAttempts] = useState(0);
52
53
  const resolvedZIndex = useResolvedOverlayZIndex(zIndex);
53
54
  const titleId = useId();
54
55
  const descriptionId = useId();
@@ -85,7 +86,7 @@ const ModalContent = forwardRef(({
85
86
  if (onCancelResult?.then !== void 0) {
86
87
  await onCancelResult;
87
88
  }
88
- closeModal();
89
+ setCancelAttempts((attempts) => attempts + 1);
89
90
  };
90
91
  const handleOk = (event) => {
91
92
  onOk?.(event);
@@ -115,7 +116,7 @@ const ModalContent = forwardRef(({
115
116
  kind: "modal",
116
117
  close: () => handleCancelRef.current(createOverlayCloseEvent(containerRef.current))
117
118
  });
118
- }, [hidden, handleCancelRef]);
119
+ }, [hidden, cancelAttempts, handleCancelRef]);
119
120
  useFocusTrap(containerRef, !hidden, {
120
121
  initialFocus: initialFocusRef ?? dialogRef
121
122
  });
@@ -3,7 +3,7 @@ import ScrollbarBase from "@synerise/ds-scrollbar";
3
3
  const ModalScrollWrap = /* @__PURE__ */ styled.div.withConfig({
4
4
  displayName: "ModalContentstyles__ModalScrollWrap",
5
5
  componentId: "sc-1sk67uc-0"
6
- })(["position:fixed;top:0;left:0;right:0;bottom:0;overflow:auto;"]);
6
+ })(["position:fixed;top:0;left:0;right:0;bottom:0;overflow:auto;scrollbar-gutter:stable;"]);
7
7
  const ModalWrapper = /* @__PURE__ */ styled.div.withConfig({
8
8
  displayName: "ModalContentstyles__ModalWrapper",
9
9
  componentId: "sc-1sk67uc-1"
@@ -1,7 +1,7 @@
1
1
  import { StyledButton } from '@synerise/ds-button';
2
2
  export declare const CloseButton: StyledButton;
3
3
  export declare const TitleContainer: import('styled-components').StyledComponent<"div", any, {}, never>;
4
- export declare const Title: import('styled-components').StyledComponent<({ level, withoutMargin, children, className, ellipsis, ...rest }: import('@synerise/ds-typography/dist/Title.types').Props) => React.JSX.Element, any, {}, never>;
4
+ export declare const Title: import('styled-components').StyledComponent<({ level, withoutMargin, children, className, ellipsis, ...rest }: import('@synerise/ds-typography/dist/Title.types.js').Props) => React.JSX.Element, any, {}, never>;
5
5
  export declare const ActionButtons: import('styled-components').StyledComponent<"div", any, {}, never>;
6
6
  export declare const BottomBar: import('styled-components').StyledComponent<"div", any, {}, never>;
7
7
  export declare const ModalHeaderTop: import('styled-components').StyledComponent<"div", any, {}, never>;
@@ -16,6 +16,9 @@ export type ModalSize = 'small' | 'medium' | 'large' | 'extraLarge' | 'fullSize'
16
16
  * Handler for the OK / Cancel buttons. May be synchronous or return a
17
17
  * `Promise` — when a promise is returned, the modal stays open until it
18
18
  * resolves.
19
+ *
20
+ * `onCancel` is a request to close, not the close itself: lower `open` to
21
+ * close, or leave it alone to keep the modal up.
19
22
  */
20
23
  type ModalButtonHandler = ((e: MouseEvent<HTMLElement>) => void) | ((e: MouseEvent<HTMLElement>) => Promise<unknown>);
21
24
  /** Props for the {@link Modal} component. */
@@ -89,12 +92,15 @@ export type ModalProps = {
89
92
  */
90
93
  closable?: boolean;
91
94
  /**
92
- * Whether clicking the backdrop closes the modal.
95
+ * Whether clicking the backdrop requests a close.
93
96
  * @defaultValue `true`
94
97
  */
95
98
  maskClosable?: boolean;
96
99
  /**
97
- * Whether the modal is visible.
100
+ * Whether the modal is visible, and the only thing that hides it. The close
101
+ * button, `Escape`, the backdrop and `closeAllOverlays` call `onCancel` and
102
+ * leave this prop alone; the modal closes itself only when there is no
103
+ * `onCancel` to ask.
98
104
  * @defaultValue `false`
99
105
  */
100
106
  open?: boolean;
package/dist/ShowModal.js CHANGED
@@ -1,8 +1,23 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
+ import { useState } from "react";
2
3
  import { setPortalContent } from "@synerise/ds-core";
3
4
  import { Modal } from "./Modal.js";
4
5
  let modalInstanceId = 0;
5
6
  const isThenable = (value) => !!value && typeof value.then === "function";
7
+ const ImperativeModal = ({
8
+ onCancel,
9
+ ...props
10
+ }) => {
11
+ const [open, setOpen] = useState(true);
12
+ const handleCancel = async (event) => {
13
+ const result = onCancel?.(event);
14
+ if (isThenable(result)) {
15
+ await result;
16
+ }
17
+ setOpen(false);
18
+ };
19
+ return /* @__PURE__ */ jsx(Modal, { ...props, open, onCancel: onCancel ? handleCancel : void 0 });
20
+ };
6
21
  const showModal = ({
7
22
  onOk,
8
23
  afterClose,
@@ -22,7 +37,7 @@ const showModal = ({
22
37
  }
23
38
  };
24
39
  modalInstanceId += 1;
25
- setPortalContent(/* @__PURE__ */ jsx(Modal, { ...initial, open: true, onOk: onOk ? handleOk : void 0, afterClose: () => {
40
+ setPortalContent(/* @__PURE__ */ jsx(ImperativeModal, { ...initial, onOk: onOk ? handleOk : void 0, afterClose: () => {
26
41
  afterClose?.();
27
42
  cleanup();
28
43
  } }, modalInstanceId));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-modal",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "Modal UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "synerise/synerise-design",
@@ -39,16 +39,16 @@
39
39
  "sideEffects": false,
40
40
  "types": "dist/index.d.ts",
41
41
  "dependencies": {
42
- "@synerise/ds-button": "^2.2.0",
43
- "@synerise/ds-icon": "^2.3.0",
44
- "@synerise/ds-scrollbar": "^2.1.0",
45
- "@synerise/ds-tabs": "^2.1.0",
46
- "@synerise/ds-typography": "^2.1.0",
47
- "@synerise/ds-utils": "^2.3.0"
42
+ "@synerise/ds-button": "^2.2.1",
43
+ "@synerise/ds-icon": "^2.3.1",
44
+ "@synerise/ds-scrollbar": "^2.1.1",
45
+ "@synerise/ds-tabs": "^2.1.1",
46
+ "@synerise/ds-typography": "^2.1.1",
47
+ "@synerise/ds-utils": "^2.3.1"
48
48
  },
49
49
  "devDependencies": {
50
- "@synerise/ds-dropdown": "^2.2.0",
51
- "@synerise/ds-popconfirm": "^2.1.0",
50
+ "@synerise/ds-dropdown": "^2.2.1",
51
+ "@synerise/ds-popconfirm": "^2.1.1",
52
52
  "vitest": "4"
53
53
  },
54
54
  "peerDependencies": {
@@ -58,5 +58,5 @@
58
58
  "react-intl": ">=3.12.0 <= 6.8",
59
59
  "styled-components": "^5.3.3"
60
60
  },
61
- "gitHead": "5c3d61e30289486d14c7d6becb682e2d4a08ce41"
61
+ "gitHead": "2d2a540b35fddf8855da45f0dec2f4612c6d87b6"
62
62
  }