x-ui-design 0.9.21 → 0.9.22

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.js CHANGED
@@ -2620,7 +2620,7 @@ const ConditionalWrapper = ({
2620
2620
  children
2621
2621
  }) => condition ? wrapper(children) : children;
2622
2622
 
2623
- const OFFSET = 12;
2623
+ const OFFSET = 11;
2624
2624
  const usePopupPosition = ({
2625
2625
  open,
2626
2626
  setOpen,
@@ -2632,6 +2632,7 @@ const usePopupPosition = ({
2632
2632
  const [_placement, _setPlacement] = React.useState(placement ?? "bottomLeft");
2633
2633
  const [popupPosition, setPopupPosition] = React.useState({});
2634
2634
  const inBody = React.useMemo(() => popupContainer?.tagName === 'BODY', [popupContainer]);
2635
+ const popupRect = React.useMemo(() => popupRef.current?.getBoundingClientRect(), [popupRef.current]);
2635
2636
  const calculatePosition = React.useCallback(e => {
2636
2637
  const container = targetRef.current?.getBoundingClientRect();
2637
2638
  if (!container) {
@@ -2660,8 +2661,7 @@ const usePopupPosition = ({
2660
2661
  setPopupPosition({});
2661
2662
  return;
2662
2663
  }
2663
- if (popupRef.current) {
2664
- const popupRect = popupRef.current?.getBoundingClientRect();
2664
+ if (popupRect) {
2665
2665
  const availableSpace = {
2666
2666
  top: container.top - (popupRect.height + OFFSET),
2667
2667
  bottom: (inBody ? window.innerHeight : scrollableParents?.clientHeight || 0) - (container.bottom + popupRect.height + OFFSET),
@@ -2696,7 +2696,7 @@ const usePopupPosition = ({
2696
2696
  case "bottom":
2697
2697
  setPopupPosition({
2698
2698
  top: positions.top + container.height,
2699
- left: positions.left + (container.width || 0) / 2 - (popupRef.current?.offsetWidth || 0) / 2
2699
+ left: positions.left + (container.width || 0) / 2 - (popupRect?.width || 0) / 2
2700
2700
  });
2701
2701
  break;
2702
2702
  case "bottomLeft":
@@ -2708,31 +2708,31 @@ const usePopupPosition = ({
2708
2708
  case "bottomRight":
2709
2709
  setPopupPosition({
2710
2710
  top: positions.top + container.height,
2711
- left: positions.left + (container.width || 0) - (popupRef.current?.offsetWidth || 0)
2711
+ left: positions.left + (container.width || 0) - (popupRect?.width || 0)
2712
2712
  });
2713
2713
  break;
2714
2714
  case "top":
2715
2715
  setPopupPosition({
2716
- top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
2717
- left: positions.left + (container.width || 0) / 2 - (popupRef.current?.offsetWidth || 0) / 2
2716
+ top: positions.top - (popupRect?.height || 0) - OFFSET * 2,
2717
+ left: positions.left + (container.width || 0) / 2 - (popupRect?.width || 0) / 2
2718
2718
  });
2719
2719
  break;
2720
2720
  case "topLeft":
2721
2721
  setPopupPosition({
2722
- top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
2722
+ top: positions.top - (popupRect?.height || 0) - OFFSET * 2,
2723
2723
  left: positions.left
2724
2724
  });
2725
2725
  break;
2726
2726
  case "topRight":
2727
2727
  setPopupPosition({
2728
- top: positions.top - (popupRef.current?.clientHeight || 0) - OFFSET * 2,
2729
- left: positions.left + (container.width || 0) - (popupRef.current?.offsetWidth || 0)
2728
+ top: positions.top - (popupRect?.height || 0) - OFFSET * 2,
2729
+ left: positions.left + (container.width || 0) - (popupRect?.width || 0)
2730
2730
  });
2731
2731
  break;
2732
2732
  }
2733
2733
  };
2734
2734
  _calculation();
2735
- }, [targetRef, popupContainer, popupRef, inBody, _placement, setOpen]);
2735
+ }, [targetRef, popupContainer, popupRect, inBody, _placement, setOpen]);
2736
2736
  React.useEffect(() => {
2737
2737
  if (!open) {
2738
2738
  return;
@@ -2746,7 +2746,6 @@ const usePopupPosition = ({
2746
2746
  scrollableParents
2747
2747
  } = getElementParentDetails(targetRef.current, true);
2748
2748
  scrollableParents?.addEventListener("scroll", calculatePosition, options);
2749
- // setPositionRelative('relative');
2750
2749
  calculatePosition();
2751
2750
  document.body.addEventListener("scroll", calculatePosition, options);
2752
2751
  document.body.addEventListener("resize", calculatePosition, options);
@@ -2754,13 +2753,13 @@ const usePopupPosition = ({
2754
2753
  controller.abort();
2755
2754
  setPopupPosition({});
2756
2755
  };
2757
- }, [open, calculatePosition]);
2756
+ }, [open, targetRef, calculatePosition]);
2758
2757
  return {
2759
2758
  _placement,
2760
2759
  popupStyle: {
2761
2760
  zIndex: 10000,
2762
2761
  position: "absolute",
2763
- opacity: Object.keys(popupPosition).length ? 1 : 0,
2762
+ opacity: Object.keys(popupPosition).length && popupRect?.width ? 1 : 0,
2764
2763
  ...popupPosition
2765
2764
  }
2766
2765
  };
@@ -5573,7 +5572,7 @@ function MenuInner({
5573
5572
  className: `${prefixCls}-menu`,
5574
5573
  ref: menuRef,
5575
5574
  role: "menu"
5576
- }, items.map(it => /*#__PURE__*/React.createElement("li", {
5575
+ }, items?.map(it => /*#__PURE__*/React.createElement("li", {
5577
5576
  key: it.key,
5578
5577
  role: "menuitem",
5579
5578
  tabIndex: it.disabled ? -1 : 0,