x-ui-design 0.9.16 → 0.9.17
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/dist/index.esm.js +17 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +17 -8
- package/dist/index.js.map +1 -1
- package/lib/hooks/usePopupPosition.ts +21 -9
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -2653,13 +2653,18 @@ const usePopupPosition = ({
|
|
|
2653
2653
|
top: (relativePosition.top || 0) + (targetRef.current?.offsetTop || 0) - (scrollableParents?.offsetTop || 0) + OFFSET,
|
|
2654
2654
|
left: relativePosition.left + (targetRef.current?.offsetLeft || 0) - (targetRef.current?.clientWidth || 0) / 2
|
|
2655
2655
|
};
|
|
2656
|
-
if (
|
|
2656
|
+
if (e?.target === scrollableParents && inBody) {
|
|
2657
|
+
setOpen(false);
|
|
2658
|
+
setPopupPosition({});
|
|
2659
|
+
return;
|
|
2660
|
+
}
|
|
2661
|
+
if (popupRef.current) {
|
|
2657
2662
|
const popupRect = popupRef.current.getBoundingClientRect();
|
|
2658
2663
|
const availableSpace = {
|
|
2659
2664
|
top: container.top - (popupRect.height + OFFSET),
|
|
2660
|
-
bottom: (scrollableParents?.clientHeight || 0) - (container.bottom + popupRect.height + OFFSET),
|
|
2665
|
+
bottom: (inBody ? window.innerHeight : scrollableParents?.clientHeight || 0) - (container.bottom + popupRect.height + OFFSET),
|
|
2661
2666
|
left: container.left - (popupRect.width + OFFSET),
|
|
2662
|
-
right: (scrollableParents?.clientWidth || 0) - (container.right + popupRect.width + OFFSET)
|
|
2667
|
+
right: (inBody ? window.innerWidth : scrollableParents?.clientWidth || 0) - (container.right + popupRect.width + OFFSET)
|
|
2663
2668
|
};
|
|
2664
2669
|
let newPlacement = _placement;
|
|
2665
2670
|
if (availableSpace.bottom < 0 && availableSpace.top > 0) {
|
|
@@ -2674,13 +2679,16 @@ const usePopupPosition = ({
|
|
|
2674
2679
|
if (availableSpace.right < 0 && availableSpace.left > 0) {
|
|
2675
2680
|
newPlacement = newPlacement.replace('Left', 'Right');
|
|
2676
2681
|
}
|
|
2682
|
+
if (availableSpace.right < 0 && availableSpace.left < 0) {
|
|
2683
|
+
if (newPlacement.includes('Right')) {
|
|
2684
|
+
positions.left = popupRef.current.clientWidth - positions.left + container.left;
|
|
2685
|
+
}
|
|
2686
|
+
if (newPlacement.includes('Left')) {
|
|
2687
|
+
positions.left = positions.left - popupRef.current.clientWidth + container.width;
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2677
2690
|
_setPlacement(newPlacement);
|
|
2678
2691
|
}
|
|
2679
|
-
if (e?.target === scrollableParents && inBody) {
|
|
2680
|
-
setOpen(false);
|
|
2681
|
-
setPopupPosition({});
|
|
2682
|
-
return;
|
|
2683
|
-
}
|
|
2684
2692
|
const _calculation = () => {
|
|
2685
2693
|
switch (_placement) {
|
|
2686
2694
|
case "bottom":
|
|
@@ -2748,6 +2756,7 @@ const usePopupPosition = ({
|
|
|
2748
2756
|
document.body.addEventListener("resize", calculatePosition, options);
|
|
2749
2757
|
return () => {
|
|
2750
2758
|
controller.abort();
|
|
2759
|
+
setPopupPosition({});
|
|
2751
2760
|
// setPositionRelative('unset');
|
|
2752
2761
|
};
|
|
2753
2762
|
}, [open, targetRef, popupContainer, inBody, calculatePosition]);
|