x-ui-design 0.8.77 → 0.8.79

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
@@ -2607,6 +2607,12 @@ const usePosition = ({
2607
2607
  }) => {
2608
2608
  const [showPlacement, setShowPlacement] = useState('');
2609
2609
  const [_dropdownPosition, setDropdownPosition] = useState({});
2610
+ const isTop = placement === 'top';
2611
+ const isLeft = placement === 'left';
2612
+ const isRight = placement === 'right';
2613
+ const isBottom = placement === 'bottom';
2614
+ const hasLeft = placement?.toLowerCase()?.includes('left');
2615
+ const hasRight = placement?.toLowerCase()?.includes('right');
2610
2616
  const dropdownPosition = useCallback(() => {
2611
2617
  if (!triggerRef.current) {
2612
2618
  return {};
@@ -2617,18 +2623,12 @@ const usePosition = ({
2617
2623
  const spaceAbove = inputRect.top - containerRect.top;
2618
2624
  const spaceBelow = containerRect.bottom - inputRect.bottom;
2619
2625
  const _shouldShowAbove = spaceBelow < dropdownHeight && spaceAbove > dropdownHeight;
2620
- const hasLeft = placement?.toLowerCase()?.includes('left');
2621
- const hasRight = placement?.toLowerCase()?.includes('right');
2622
- const isLeft = placement === 'left';
2623
- const isRight = placement === 'right';
2624
- const isBottom = placement === 'bottom';
2625
- const isTop = placement === 'top';
2626
2626
  setShowPlacement(`${prefixCls}-${_shouldShowAbove ? 'top' : 'bottom'}${hasRight ? 'Right' : hasLeft ? 'Left' : ''}${isBottom || isTop ? 'Left' : 'Right'} ${placement}`);
2627
2627
  if (getPopupContainer) {
2628
2628
  const leftPosition = hasRight ? isRight ? (inputRect.left || 0) + (triggerRef.current?.offsetWidth || 0) + offset : (inputRect.left || 0) + (triggerRef.current?.offsetWidth || 0) - (popupRef.current?.offsetWidth || 0) : isLeft ? (inputRect.left || 0) + document.documentElement.scrollLeft - (popupRef.current?.offsetWidth || 0) - offset : (inputRect.left || 0) + document.documentElement.scrollLeft;
2629
2629
  const _top = isRight || isLeft ? (inputRect.top || 0) + (popupRef.current?.offsetHeight || 0) + document.documentElement.scrollTop + offset * 2 : (inputRect.top || 0) + document.documentElement.scrollTop;
2630
2630
  setDropdownPosition({
2631
- top: _shouldShowAbove ? _top - (popupRef.current?.offsetHeight || 0) + 4 - (offset !== 4 ? offset * 2 : 0) : _top + (triggerRef.current?.offsetHeight || 0) + offset,
2631
+ top: _shouldShowAbove || isLeft || isRight ? _top - (popupRef.current?.offsetHeight || 0) + 4 - (offset !== 4 ? offset * 2 : 0) : _top + (triggerRef.current?.offsetHeight || 0) + offset,
2632
2632
  left: leftPosition
2633
2633
  });
2634
2634
  } else {
@@ -2644,7 +2644,7 @@ const usePosition = ({
2644
2644
  });
2645
2645
  } else {
2646
2646
  setDropdownPosition({
2647
- top: (_shouldShowAbove ? triggerRef.current.offsetTop - (popupRef.current?.offsetHeight || dropdownHeight) - offset * 2 : triggerRef.current.offsetTop + triggerRef.current?.offsetHeight) + offset,
2647
+ top: (_shouldShowAbove || isLeft || isRight ? triggerRef.current.offsetTop - (popupRef.current?.offsetHeight || dropdownHeight) - offset * 2 : triggerRef.current.offsetTop + triggerRef.current?.offsetHeight) + offset,
2648
2648
  ...(hasRight ? {
2649
2649
  left: triggerRef.current.offsetLeft + (triggerRef.current?.offsetWidth || 0) - (popupRef.current?.offsetWidth || 0) / placementPositionOffset
2650
2650
  } : {
@@ -2653,7 +2653,7 @@ const usePosition = ({
2653
2653
  });
2654
2654
  }
2655
2655
  }
2656
- }, [offset, popupRef, prefixCls, placement, triggerRef, getPopupContainer, placementPositionOffset]);
2656
+ }, [isTop, isLeft, isRight, hasLeft, hasRight, isBottom, offset, popupRef, prefixCls, placement, triggerRef, getPopupContainer, placementPositionOffset]);
2657
2657
  useEffect(() => {
2658
2658
  if (!isOpen) return;
2659
2659
  const _dropdownPosition = () => dropdownPosition();
@@ -5425,7 +5425,7 @@ const Dropdown = ({
5425
5425
  };
5426
5426
  const popup = /*#__PURE__*/React.createElement(ConditionalWrapper, {
5427
5427
  condition: getPopupContainer !== undefined,
5428
- wrapper: element => getPopupContainer ? /*#__PURE__*/createPortal(element, getPopupContainer(popupRef.current)) : /*#__PURE__*/React.createElement(React.Fragment, null, element)
5428
+ wrapper: element => getPopupContainer ? /*#__PURE__*/createPortal(element, getPopupContainer(triggerRef.current)) : /*#__PURE__*/React.createElement(React.Fragment, null, element)
5429
5429
  }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
5430
5430
  ref: popupRef,
5431
5431
  className: `${prefixCls}-overlay ${prefixCls}-${placement} ${overlayClassName}`,