x-ui-design 0.9.18 → 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 CHANGED
@@ -2640,15 +2640,10 @@ const usePopupPosition = ({
2640
2640
  relativePosition
2641
2641
  } = getElementParentDetails(targetRef.current, true);
2642
2642
  const _containsElement = scrollableParents?.contains(popupContainer) && popupContainer !== scrollableParents;
2643
- console.info({
2644
- container,
2645
- scrollableParents,
2646
- relativePosition,
2647
- positions: !popupContainer,
2648
- _containsElement,
2649
- inBody,
2650
- popupRef
2651
- });
2643
+ const popupRect = popupRef.current?.getBoundingClientRect();
2644
+ if (!popupRect?.width) {
2645
+ return;
2646
+ }
2652
2647
  const positions = !popupContainer ? {
2653
2648
  top: (targetRef.current?.offsetTop || 0) + OFFSET,
2654
2649
  left: targetRef.current?.offsetLeft || 0
@@ -2667,18 +2662,13 @@ const usePopupPosition = ({
2667
2662
  setPopupPosition({});
2668
2663
  return;
2669
2664
  }
2670
- if (popupRef.current) {
2671
- const popupRect = popupRef.current.getBoundingClientRect();
2665
+ if (popupRect) {
2672
2666
  const availableSpace = {
2673
2667
  top: container.top - (popupRect.height + OFFSET),
2674
2668
  bottom: (inBody ? window.innerHeight : scrollableParents?.clientHeight || 0) - (container.bottom + popupRect.height + OFFSET),
2675
2669
  left: container.left - (popupRect.width + OFFSET),
2676
2670
  right: (inBody ? window.innerWidth : scrollableParents?.clientWidth || 0) - (container.right + popupRect.width + OFFSET)
2677
2671
  };
2678
- console.info({
2679
- popupRect,
2680
- availableSpace
2681
- });
2682
2672
  let newPlacement = _placement;
2683
2673
  if (availableSpace.bottom < 0 && availableSpace.top > 0) {
2684
2674
  newPlacement = newPlacement.replace('bottom', 'top');
@@ -2694,10 +2684,10 @@ const usePopupPosition = ({
2694
2684
  }
2695
2685
  if (availableSpace.right < 0 && availableSpace.left < 0) {
2696
2686
  if (newPlacement.includes('Right')) {
2697
- positions.left = popupRef.current.clientWidth - positions.left + container.left;
2687
+ positions.left = popupRect.width - positions.left + container.left;
2698
2688
  }
2699
2689
  if (newPlacement.includes('Left')) {
2700
- positions.left = positions.left - popupRef.current.clientWidth + container.width;
2690
+ positions.left = positions.left - popupRect.width + container.width;
2701
2691
  }
2702
2692
  }
2703
2693
  _setPlacement(newPlacement);
@@ -2743,7 +2733,7 @@ const usePopupPosition = ({
2743
2733
  }
2744
2734
  };
2745
2735
  _calculation();
2746
- }, [targetRef, popupRef, popupContainer, inBody, _placement, setOpen]);
2736
+ }, [targetRef, popupContainer, popupRef.current, inBody, _placement, setOpen]);
2747
2737
  useEffect(() => {
2748
2738
  if (!open) {
2749
2739
  return;