@likable-hair/svelte 3.0.69 → 3.0.70
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.
|
@@ -19,11 +19,12 @@ function calculateMenuPosition(params) {
|
|
|
19
19
|
let activatorHeight = params.activator.offsetHeight;
|
|
20
20
|
_top = activatorTop + activatorHeight + _activatorGap;
|
|
21
21
|
_left = activatorLeft;
|
|
22
|
-
let { top: fixedParentTop, left: fixedParentLeft,
|
|
23
|
-
|
|
22
|
+
let { top: fixedParentTop, left: fixedParentLeft, fixedParent, validStickyParent } = getParentInstanceFromViewport(activator?.parentElement);
|
|
23
|
+
console.log(validStickyParent);
|
|
24
|
+
if (!!fixedParent) {
|
|
24
25
|
_top = _top - fixedParentTop;
|
|
25
26
|
_left = _left - fixedParentLeft;
|
|
26
|
-
} else {
|
|
27
|
+
} else if (!validStickyParent) {
|
|
27
28
|
_top = _top + window.scrollY;
|
|
28
29
|
_left = _left + window.scrollX;
|
|
29
30
|
}
|
|
@@ -34,11 +35,12 @@ function calculateMenuPosition(params) {
|
|
|
34
35
|
let menuWidth = params.menuElement.offsetWidth;
|
|
35
36
|
_top = activatorTop + activatorHeight + _activatorGap;
|
|
36
37
|
_left = activatorLeft;
|
|
37
|
-
let { top: fixedParentTop, left: fixedParentLeft,
|
|
38
|
-
|
|
38
|
+
let { top: fixedParentTop, left: fixedParentLeft, fixedParent, validStickyParent } = getParentInstanceFromViewport(activator?.parentElement);
|
|
39
|
+
console.log(validStickyParent);
|
|
40
|
+
if (!!fixedParent) {
|
|
39
41
|
_top = _top - fixedParentTop;
|
|
40
42
|
_left = _left - fixedParentLeft;
|
|
41
|
-
} else {
|
|
43
|
+
} else if (!validStickyParent) {
|
|
42
44
|
_top = _top + window.scrollY;
|
|
43
45
|
_left = _left + window.scrollX;
|
|
44
46
|
}
|
|
@@ -173,7 +175,9 @@ function handleCloseControllerClick() {
|
|
|
173
175
|
function getParentInstanceFromViewport(activatorParent) {
|
|
174
176
|
let top = 0;
|
|
175
177
|
let left = 0;
|
|
176
|
-
let
|
|
178
|
+
let fixedParent = void 0;
|
|
179
|
+
let stickyParent = !!activatorParent && getComputedStyle(activatorParent).position === "sticky" ? activatorParent : void 0;
|
|
180
|
+
let isStickyValid = false;
|
|
177
181
|
while (!!activatorParent && activatorParent.nodeName.toLowerCase() !== "html" && activatorParent.nodeName.toLowerCase() !== "body") {
|
|
178
182
|
const currentParent = activatorParent.parentElement;
|
|
179
183
|
if (!currentParent)
|
|
@@ -185,19 +189,21 @@ function getParentInstanceFromViewport(activatorParent) {
|
|
|
185
189
|
const boundingClientRect = activatorParent.getBoundingClientRect();
|
|
186
190
|
top = top + boundingClientRect.top;
|
|
187
191
|
left = left + boundingClientRect.left;
|
|
188
|
-
|
|
192
|
+
fixedParent = activatorParent;
|
|
193
|
+
}
|
|
194
|
+
if (position === "sticky") {
|
|
195
|
+
stickyParent = activatorParent;
|
|
196
|
+
}
|
|
197
|
+
if (position === "relative" && !!stickyParent) {
|
|
198
|
+
isStickyValid = true;
|
|
189
199
|
}
|
|
190
200
|
activatorParent = activatorParent.parentElement;
|
|
191
201
|
}
|
|
192
|
-
return { top, left,
|
|
202
|
+
return { top, left, fixedParent, validStickyParent: isStickyValid ? stickyParent : void 0 };
|
|
193
203
|
}
|
|
194
204
|
function handleWindowScrollOrResize() {
|
|
195
|
-
if (open && !!menuElement && !!activator)
|
|
196
|
-
let elem = getPositionedAncestor(menuElement.parentElement);
|
|
197
|
-
if (!!elem && getComputedStyle(elem).position == "sticky")
|
|
198
|
-
return;
|
|
205
|
+
if (open && !!menuElement && !!activator)
|
|
199
206
|
calculateMenuPosition({ menuElement, activator });
|
|
200
|
-
}
|
|
201
207
|
}
|
|
202
208
|
function handleMenuClick(e, zIndex2) {
|
|
203
209
|
let otherMenus = document.querySelectorAll(`[data-menu]`);
|
|
@@ -235,7 +241,7 @@ function handleMenuClick(e, zIndex2) {
|
|
|
235
241
|
data-menu
|
|
236
242
|
data-uid={currentUid}
|
|
237
243
|
style:z-index={zIndex}
|
|
238
|
-
style:position=
|
|
244
|
+
style:position="absolute"
|
|
239
245
|
style:top={_top + "px"}
|
|
240
246
|
style:box-shadow={_boxShadow}
|
|
241
247
|
style:border-radius={_borderRadius}
|