x-ui-design 0.9.19 → 0.9.20
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 +6 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +6 -7
- package/dist/index.js.map +1 -1
- package/lib/hooks/usePopupPosition.ts +16 -9
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -2640,6 +2640,10 @@ const usePopupPosition = ({
|
|
|
2640
2640
|
relativePosition
|
|
2641
2641
|
} = getElementParentDetails(targetRef.current, true);
|
|
2642
2642
|
const _containsElement = scrollableParents?.contains(popupContainer) && popupContainer !== scrollableParents;
|
|
2643
|
+
const popupRect = popupRef.current?.getBoundingClientRect();
|
|
2644
|
+
if (!popupRect?.width) {
|
|
2645
|
+
return;
|
|
2646
|
+
}
|
|
2643
2647
|
const positions = !popupContainer ? {
|
|
2644
2648
|
top: (targetRef.current?.offsetTop || 0) + OFFSET,
|
|
2645
2649
|
left: targetRef.current?.offsetLeft || 0
|
|
@@ -2658,18 +2662,13 @@ const usePopupPosition = ({
|
|
|
2658
2662
|
setPopupPosition({});
|
|
2659
2663
|
return;
|
|
2660
2664
|
}
|
|
2661
|
-
if (
|
|
2662
|
-
const popupRect = popupRef.current.getBoundingClientRect();
|
|
2665
|
+
if (popupRect) {
|
|
2663
2666
|
const availableSpace = {
|
|
2664
2667
|
top: container.top - (popupRect.height + OFFSET),
|
|
2665
2668
|
bottom: (inBody ? window.innerHeight : scrollableParents?.clientHeight || 0) - (container.bottom + popupRect.height + OFFSET),
|
|
2666
2669
|
left: container.left - (popupRect.width + OFFSET),
|
|
2667
2670
|
right: (inBody ? window.innerWidth : scrollableParents?.clientWidth || 0) - (container.right + popupRect.width + OFFSET)
|
|
2668
2671
|
};
|
|
2669
|
-
console.info({
|
|
2670
|
-
popupRect,
|
|
2671
|
-
availableSpace
|
|
2672
|
-
});
|
|
2673
2672
|
let newPlacement = _placement;
|
|
2674
2673
|
if (availableSpace.bottom < 0 && availableSpace.top > 0) {
|
|
2675
2674
|
newPlacement = newPlacement.replace('bottom', 'top');
|
|
@@ -2734,7 +2733,7 @@ const usePopupPosition = ({
|
|
|
2734
2733
|
}
|
|
2735
2734
|
};
|
|
2736
2735
|
_calculation();
|
|
2737
|
-
}, [targetRef, popupRef.current,
|
|
2736
|
+
}, [targetRef, popupContainer, popupRef.current, inBody, _placement, setOpen]);
|
|
2738
2737
|
useEffect(() => {
|
|
2739
2738
|
if (!open) {
|
|
2740
2739
|
return;
|