@sb1/ffe-modals-react 1.1.38 → 1.2.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.
package/es/Modal.js CHANGED
@@ -33,14 +33,24 @@ export var Modal = React.forwardRef(function (_a, ref) {
33
33
  var htmlOverflowY = useRef(isClient ? document.documentElement.style.overflowY : '');
34
34
  useImperativeHandle(ref, function () { return ({
35
35
  open: function () {
36
- var _a;
37
- setIsOpen(true);
38
- (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.showModal();
36
+ // Prevent opening an already open modal
37
+ if (!isOpen && dialogRef.current) {
38
+ setIsOpen(true);
39
+ dialogRef.current.showModal();
40
+ }
39
41
  },
40
42
  close: function () {
41
- var _a;
42
- (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.close();
43
+ // Prevent closing an already closed modal
44
+ if (isOpen && dialogRef.current) {
45
+ dialogRef.current.close();
46
+ }
47
+ },
48
+ // Expose isOpen state
49
+ get isOpen() {
50
+ return isOpen;
43
51
  },
52
+ // Expose dialogRef directly
53
+ dialogRef: dialogRef,
44
54
  }); });
45
55
  useEffect(function () {
46
56
  setIsClient(true);
package/lib/Modal.js CHANGED
@@ -72,14 +72,24 @@ exports.Modal = react_1.default.forwardRef(function (_a, ref) {
72
72
  var htmlOverflowY = (0, react_1.useRef)(isClient ? document.documentElement.style.overflowY : '');
73
73
  (0, react_1.useImperativeHandle)(ref, function () { return ({
74
74
  open: function () {
75
- var _a;
76
- setIsOpen(true);
77
- (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.showModal();
75
+ // Prevent opening an already open modal
76
+ if (!isOpen && dialogRef.current) {
77
+ setIsOpen(true);
78
+ dialogRef.current.showModal();
79
+ }
78
80
  },
79
81
  close: function () {
80
- var _a;
81
- (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.close();
82
+ // Prevent closing an already closed modal
83
+ if (isOpen && dialogRef.current) {
84
+ dialogRef.current.close();
85
+ }
86
+ },
87
+ // Expose isOpen state
88
+ get isOpen() {
89
+ return isOpen;
82
90
  },
91
+ // Expose dialogRef directly
92
+ dialogRef: dialogRef,
83
93
  }); });
84
94
  (0, react_1.useEffect)(function () {
85
95
  setIsClient(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sb1/ffe-modals-react",
3
- "version": "1.1.38",
3
+ "version": "1.2.0",
4
4
  "license": "MIT",
5
5
  "author": "SpareBank 1",
6
6
  "files": [
@@ -26,7 +26,7 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@sb1/ffe-icons-react": "^12.0.1",
29
- "@sb1/ffe-modals": "^2.0.21",
29
+ "@sb1/ffe-modals": "^2.1.0",
30
30
  "dialog-polyfill": "^0.5.6"
31
31
  },
32
32
  "devDependencies": {
@@ -41,5 +41,5 @@
41
41
  "publishConfig": {
42
42
  "access": "public"
43
43
  },
44
- "gitHead": "fe9b0022719dca5a50cc6b135f554819f5708075"
44
+ "gitHead": "8346000c7844b20f829aebc2c955e317426b1794"
45
45
  }
package/types/Modal.d.ts CHANGED
@@ -14,5 +14,7 @@ export interface ModalProps extends React.ComponentPropsWithoutRef<'dialog'> {
14
14
  export type ModalHandle = {
15
15
  readonly open: () => void;
16
16
  readonly close: () => void;
17
+ readonly isOpen: boolean;
18
+ readonly dialogRef: React.RefObject<HTMLDialogElement>;
17
19
  };
18
20
  export declare const Modal: React.ForwardRefExoticComponent<ModalProps & React.RefAttributes<ModalHandle>>;