@andreagiugni/tailwind-dashboard-ui 0.5.17 → 0.5.18
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/README.md +1 -1
- package/dist/index.cjs +13 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +13 -4
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
package/dist/index.d.cts
CHANGED
|
@@ -83,6 +83,8 @@ interface DropdownProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
83
83
|
onClose: () => void;
|
|
84
84
|
/** Render under document.body so menus are not clipped by overflow containers. Default: true. */
|
|
85
85
|
portal?: boolean;
|
|
86
|
+
/** Optional ref to the trigger element. Useful when the trigger is not adjacent to the menu. */
|
|
87
|
+
triggerRef?: React.RefObject<HTMLElement | null>;
|
|
86
88
|
}
|
|
87
89
|
declare const Dropdown: React.FC<DropdownProps>;
|
|
88
90
|
|
package/dist/index.d.ts
CHANGED
|
@@ -83,6 +83,8 @@ interface DropdownProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
83
83
|
onClose: () => void;
|
|
84
84
|
/** Render under document.body so menus are not clipped by overflow containers. Default: true. */
|
|
85
85
|
portal?: boolean;
|
|
86
|
+
/** Optional ref to the trigger element. Useful when the trigger is not adjacent to the menu. */
|
|
87
|
+
triggerRef?: React.RefObject<HTMLElement | null>;
|
|
86
88
|
}
|
|
87
89
|
declare const Dropdown: React.FC<DropdownProps>;
|
|
88
90
|
|
package/dist/index.js
CHANGED
|
@@ -410,12 +410,20 @@ var AvatarText = ({
|
|
|
410
410
|
}
|
|
411
411
|
);
|
|
412
412
|
};
|
|
413
|
+
function getTriggerElement(anchor, triggerRef) {
|
|
414
|
+
if (triggerRef?.current) return triggerRef.current;
|
|
415
|
+
if (!anchor) return null;
|
|
416
|
+
const previous = anchor.previousElementSibling;
|
|
417
|
+
const adjacentTrigger = previous?.matches(".dropdown-toggle, button, [aria-haspopup='menu']") ? previous : previous?.querySelector(".dropdown-toggle, button, [aria-haspopup='menu']");
|
|
418
|
+
return adjacentTrigger ?? anchor.parentElement?.querySelector(".dropdown-toggle");
|
|
419
|
+
}
|
|
413
420
|
var Dropdown = ({
|
|
414
421
|
isOpen,
|
|
415
422
|
onClose,
|
|
416
423
|
children,
|
|
417
424
|
className,
|
|
418
425
|
portal = true,
|
|
426
|
+
triggerRef,
|
|
419
427
|
style,
|
|
420
428
|
...rest
|
|
421
429
|
}) => {
|
|
@@ -424,7 +432,8 @@ var Dropdown = ({
|
|
|
424
432
|
const [position, setPosition] = useState();
|
|
425
433
|
useEffect(() => {
|
|
426
434
|
const handleClickOutside = (event) => {
|
|
427
|
-
|
|
435
|
+
const trigger = getTriggerElement(anchorRef.current, triggerRef);
|
|
436
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target) && !trigger?.contains(event.target)) {
|
|
428
437
|
onClose();
|
|
429
438
|
}
|
|
430
439
|
};
|
|
@@ -432,13 +441,13 @@ var Dropdown = ({
|
|
|
432
441
|
return () => {
|
|
433
442
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
434
443
|
};
|
|
435
|
-
}, [onClose]);
|
|
444
|
+
}, [onClose, triggerRef]);
|
|
436
445
|
useLayoutEffect(() => {
|
|
437
446
|
if (!isOpen || !portal) return;
|
|
438
447
|
const updatePosition = () => {
|
|
439
448
|
const anchor = anchorRef.current;
|
|
440
449
|
const menu2 = dropdownRef.current;
|
|
441
|
-
const trigger = anchor
|
|
450
|
+
const trigger = getTriggerElement(anchor, triggerRef);
|
|
442
451
|
if (!anchor || !menu2) return;
|
|
443
452
|
const triggerRect = (trigger ?? anchor).getBoundingClientRect();
|
|
444
453
|
const menuRect = menu2.getBoundingClientRect();
|
|
@@ -459,7 +468,7 @@ var Dropdown = ({
|
|
|
459
468
|
window.removeEventListener("resize", updatePosition);
|
|
460
469
|
window.removeEventListener("scroll", updatePosition, true);
|
|
461
470
|
};
|
|
462
|
-
}, [isOpen, portal]);
|
|
471
|
+
}, [isOpen, portal, triggerRef]);
|
|
463
472
|
if (!isOpen) return null;
|
|
464
473
|
const menu = /* @__PURE__ */ jsx(
|
|
465
474
|
"div",
|