@chekinapp/ui 0.0.30 → 0.0.31

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.cjs CHANGED
@@ -2486,18 +2486,25 @@ function useModalControls(initState = false, { disabled } = {}) {
2486
2486
 
2487
2487
  // src/hooks/use-outside-click.ts
2488
2488
  var import_react16 = require("react");
2489
- function useOutsideClick(elementRef, onOutsideClick, nested) {
2489
+ function useOutsideClick({
2490
+ elementRef,
2491
+ onOutsideClick,
2492
+ triggerRef,
2493
+ isDisabled,
2494
+ nested
2495
+ }) {
2490
2496
  const handleOutsideClick = (0, import_react16.useRef)(onOutsideClick);
2491
2497
  handleOutsideClick.current = onOutsideClick;
2492
2498
  const checkNestedElements = (0, import_react16.useCallback)(
2493
- (event) => {
2499
+ (event, ownerDocument) => {
2494
2500
  const checkIsElementClickedBySelector = (selector) => {
2495
- const nestedElement = getDocument().querySelector(selector);
2501
+ const nestedElement = ownerDocument.querySelector(selector);
2496
2502
  return nestedElement?.contains(event.target);
2497
2503
  };
2498
2504
  const checkDataAttribute = () => {
2499
2505
  const target = event.target;
2500
- if (!target || !(target instanceof HTMLElement)) {
2506
+ const HTMLElementConstructor = ownerDocument.defaultView?.HTMLElement ?? HTMLElement;
2507
+ if (!target || !(target instanceof HTMLElementConstructor)) {
2501
2508
  return false;
2502
2509
  }
2503
2510
  let current = target;
@@ -2521,19 +2528,29 @@ function useOutsideClick(elementRef, onOutsideClick, nested) {
2521
2528
  [nested]
2522
2529
  );
2523
2530
  (0, import_react16.useEffect)(() => {
2531
+ if (isDisabled || !handleOutsideClick.current) {
2532
+ return;
2533
+ }
2534
+ const ownerDocument = elementRef?.current?.ownerDocument ?? triggerRef?.current?.ownerDocument ?? getDocument();
2524
2535
  function handleClickOutside(event) {
2525
- const isNestedElement = checkNestedElements(event);
2526
- if (elementRef?.current && !elementRef.current.contains(event.target) && !isNestedElement) {
2536
+ const target = event.target;
2537
+ const NodeConstructor = ownerDocument.defaultView?.Node ?? Node;
2538
+ if (!target || !(target instanceof NodeConstructor)) {
2539
+ return;
2540
+ }
2541
+ const targetNode = target;
2542
+ const isNestedElement = checkNestedElements(event, ownerDocument);
2543
+ if (elementRef?.current && !elementRef.current.contains(targetNode) && !triggerRef?.current?.contains(targetNode) && !isNestedElement) {
2527
2544
  handleOutsideClick.current?.(event);
2528
2545
  }
2529
2546
  }
2530
- getDocument().addEventListener("mousedown", handleClickOutside, true);
2531
- getDocument().addEventListener("touchstart", handleClickOutside, true);
2547
+ ownerDocument.addEventListener("mousedown", handleClickOutside, true);
2548
+ ownerDocument.addEventListener("touchstart", handleClickOutside, true);
2532
2549
  return () => {
2533
- getDocument().removeEventListener("mousedown", handleClickOutside, true);
2534
- getDocument().removeEventListener("touchstart", handleClickOutside, true);
2550
+ ownerDocument.removeEventListener("mousedown", handleClickOutside, true);
2551
+ ownerDocument.removeEventListener("touchstart", handleClickOutside, true);
2535
2552
  };
2536
- }, [checkNestedElements, elementRef]);
2553
+ }, [checkNestedElements, elementRef, isDisabled, triggerRef]);
2537
2554
  }
2538
2555
 
2539
2556
  // src/hooks/use-screen-resize.ts
@@ -11292,7 +11309,11 @@ var AirbnbSelect = React38.forwardRef(function AirbnbSelect2({
11292
11309
  const combinedRef = useCombinedRef(ref, desktopTriggerRef);
11293
11310
  const activeMobileIndex = getOptionIndex(options, pendingValue);
11294
11311
  const valueLabel = value ? getValueLabel?.(value) ?? String(value.label) : void 0;
11295
- useOutsideClick(containerRef, isOpen && !isMobile ? () => setIsOpen(false) : null);
11312
+ useOutsideClick({
11313
+ elementRef: containerRef,
11314
+ onOutsideClick: () => setIsOpen(false),
11315
+ isDisabled: !isOpen || isMobile
11316
+ });
11296
11317
  React38.useEffect(() => {
11297
11318
  if (isBlocked) {
11298
11319
  setIsOpen(false);
@@ -11792,7 +11813,11 @@ var SearchableSelectInternal = ({
11792
11813
  const triggerError = error ?? invalid;
11793
11814
  const describedBy = error && !hideErrorMessage ? errorId : void 0;
11794
11815
  const activeOptionId = highlightedIndex >= 0 ? getOptionId(reactId, highlightedIndex) : void 0;
11795
- useOutsideClick(containerRef, open && !isMobile ? () => closeSelect() : null);
11816
+ useOutsideClick({
11817
+ elementRef: containerRef,
11818
+ onOutsideClick: () => closeSelect(),
11819
+ isDisabled: !open || isMobile
11820
+ });
11796
11821
  const handleOnOpenChange = useEvent(onOpenChange);
11797
11822
  const setSelectOpen = (0, import_react63.useCallback)(
11798
11823
  (nextOpen, options2) => {