widenarrow-ui 1.1.104 → 1.1.105

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.
@@ -2,5 +2,5 @@ import { RefObject } from 'react';
2
2
  type UseHandleClickOutsideReturn = {
3
3
  ref: RefObject<HTMLDivElement>;
4
4
  };
5
- export default function useHandleClickOutside(callback: (...args: unknown[]) => void): UseHandleClickOutsideReturn;
5
+ export default function useHandleClickOutside(callback: (...args: unknown[]) => void, portalRef?: RefObject<HTMLDivElement>): UseHandleClickOutsideReturn;
6
6
  export {};
package/lib/index.esm.js CHANGED
@@ -2674,19 +2674,31 @@ var RadioButton = function (_a) {
2674
2674
  return toolTip ? (jsx(ToolTip, { className: s$k('toolTip'), text: toolTip, children: getRadioButton() })) : (getRadioButton());
2675
2675
  };
2676
2676
 
2677
- function useHandleClickOutside(callback) {
2677
+ function useHandleClickOutside(callback, portalRef) {
2678
2678
  var ref = useRef(null);
2679
2679
  useEffect(function () {
2680
2680
  var handleClickOutside = function (event) {
2681
- if (ref.current && !ref.current.contains(event.target)) {
2682
- callback();
2681
+ var target = event.target;
2682
+ var isOutsideContainer = ref.current && !ref.current.contains(target);
2683
+ var isOutsidePortal = (portalRef === null || portalRef === void 0 ? void 0 : portalRef.current) && !portalRef.current.contains(target);
2684
+ // If we have a portal ref, check if click is outside both container and portal
2685
+ // If no portal ref, just check if click is outside container
2686
+ if (portalRef === null || portalRef === void 0 ? void 0 : portalRef.current) {
2687
+ if (isOutsideContainer && isOutsidePortal) {
2688
+ callback();
2689
+ }
2690
+ }
2691
+ else {
2692
+ if (isOutsideContainer) {
2693
+ callback();
2694
+ }
2683
2695
  }
2684
2696
  };
2685
2697
  document.addEventListener('click', handleClickOutside, true);
2686
2698
  return function () {
2687
2699
  document.removeEventListener('click', handleClickOutside, true);
2688
2700
  };
2689
- }, [callback]);
2701
+ }, [callback, portalRef]);
2690
2702
  return { ref: ref };
2691
2703
  }
2692
2704
 
@@ -2757,7 +2769,7 @@ var DropDown = function (_a) {
2757
2769
  onClose();
2758
2770
  };
2759
2771
  // Close the DropDown if we click outside the DropDown
2760
- var containerRef = useHandleClickOutside(onClose).ref;
2772
+ var containerRef = useHandleClickOutside(onClose, withPortal ? { current: popperElement } : undefined).ref;
2761
2773
  // If a child has an onClickCallback, we want to close the DropDown when it is clicked.
2762
2774
  var cloneChildWithCloseCallback = function (child) {
2763
2775
  if (isValidElement(child) &&