ag-common 0.0.685 → 0.0.686

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.
@@ -90,7 +90,7 @@ const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top'
90
90
  if (portalId === undefined) {
91
91
  portalId = globalId;
92
92
  }
93
- const [elem, setElem] = (0, react_1.useState)();
93
+ const [portalElem, setPortalElem] = (0, react_1.useState)();
94
94
  (0, react_1.useEffect)(() => {
95
95
  if (portalId === null ||
96
96
  document.querySelectorAll(`#${portalId}`).length > 0) {
@@ -128,6 +128,17 @@ const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top'
128
128
  ref,
129
129
  moveMouseOutside: closeOnMoveMouseOutside,
130
130
  }, () => {
131
+ var _a;
132
+ //there might be multiple models open, only close the last one on the stack
133
+ if (portalElem) {
134
+ const myid = Array.prototype.indexOf.call(portalElem.children,
135
+ //parent because fixed background is first
136
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.parentElement);
137
+ const childcount = portalElem.children.length;
138
+ if (myid + 1 !== childcount) {
139
+ return;
140
+ }
141
+ }
131
142
  if (closeOnClickOutside && open) {
132
143
  setOpen(false);
133
144
  setBounced(false);
@@ -139,10 +150,10 @@ const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top'
139
150
  }
140
151
  }, [open, bounced]);
141
152
  (0, react_1.useEffect)(() => {
142
- if (elem === undefined && portalId) {
143
- setElem(document.getElementById(portalId));
153
+ if (portalElem === undefined && portalId) {
154
+ setPortalElem(document.getElementById(portalId));
144
155
  }
145
- }, [elem, portalId]);
156
+ }, [portalElem, portalId]);
146
157
  if (!open) {
147
158
  return react_1.default.createElement(react_1.default.Fragment, null);
148
159
  }
@@ -150,11 +161,11 @@ const Modal = ({ open, setOpen, children, position = 'left', topPosition = 'top'
150
161
  react_1.default.createElement(ModalBase, { "data-bounced": bounced, "data-position": position, "data-topposition": topPosition, ref: ref, className: className, style: style },
151
162
  showCloseButton && (react_1.default.createElement(CloseStyled, { "data-type": "modal-close", onClick: () => setOpen(false) })),
152
163
  children)));
153
- if (portalId && elem === undefined) {
164
+ if (portalId && portalElem === undefined) {
154
165
  return null;
155
166
  }
156
- if (portalId && elem) {
157
- return (0, react_dom_1.createPortal)(Content, elem);
167
+ if (portalId && portalElem) {
168
+ return (0, react_dom_1.createPortal)(Content, portalElem);
158
169
  }
159
170
  return Content;
160
171
  };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.685",
2
+ "version": "0.0.686",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",