@mirohq/design-system-dropdown-menu 4.4.10-dropdown-on-pointerup.1 → 4.4.10
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/main.js +46 -88
- package/dist/main.js.map +1 -1
- package/dist/module.js +47 -89
- package/dist/module.js.map +1 -1
- package/package.json +7 -8
package/dist/module.js
CHANGED
|
@@ -14,8 +14,7 @@ import { useLayoutEffect } from '@mirohq/design-system-use-layout-effect';
|
|
|
14
14
|
import { useAriaDisabled as useAriaDisabled$1 } from '@mirohq/design-system-use-aria-disabled';
|
|
15
15
|
import { ScrollArea } from '@mirohq/design-system-scroll-area';
|
|
16
16
|
import { styles, Thumb } from '@mirohq/design-system-base-switch';
|
|
17
|
-
import {
|
|
18
|
-
import { usePress } from '@mirohq/design-system-use-press';
|
|
17
|
+
import { isVirtualClick } from '@react-aria/utils';
|
|
19
18
|
import { styles as styles$1, isIconComponent } from '@mirohq/design-system-base-icon';
|
|
20
19
|
|
|
21
20
|
const ItemDescription = styled(Primitive.div, {
|
|
@@ -455,25 +454,16 @@ const ScrollableContent = ({
|
|
|
455
454
|
const DropdownContext = createContext({});
|
|
456
455
|
const DropdownProvider = ({
|
|
457
456
|
children,
|
|
458
|
-
open: rootOpen,
|
|
459
457
|
...restProps
|
|
460
|
-
}) =>
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
open,
|
|
470
|
-
setOpen,
|
|
471
|
-
triggerRef
|
|
472
|
-
},
|
|
473
|
-
children
|
|
474
|
-
}
|
|
475
|
-
);
|
|
476
|
-
};
|
|
458
|
+
}) => /* @__PURE__ */ jsx(
|
|
459
|
+
DropdownContext.Provider,
|
|
460
|
+
{
|
|
461
|
+
value: {
|
|
462
|
+
...restProps
|
|
463
|
+
},
|
|
464
|
+
children
|
|
465
|
+
}
|
|
466
|
+
);
|
|
477
467
|
const useDropdownContext = () => useContext(DropdownContext);
|
|
478
468
|
|
|
479
469
|
const Content = React.forwardRef(
|
|
@@ -490,11 +480,10 @@ const Content = React.forwardRef(
|
|
|
490
480
|
containerSpacing = "medium",
|
|
491
481
|
overflow = "visible",
|
|
492
482
|
maxHeight,
|
|
493
|
-
onInteractOutside,
|
|
494
483
|
children,
|
|
495
484
|
...restProps
|
|
496
485
|
}, forwardRef) => {
|
|
497
|
-
const { direction
|
|
486
|
+
const { direction } = useDropdownContext();
|
|
498
487
|
return /* @__PURE__ */ jsx(ContentProvider, { containerSpacing, children: /* @__PURE__ */ jsx(
|
|
499
488
|
StyledContent,
|
|
500
489
|
{
|
|
@@ -509,12 +498,6 @@ const Content = React.forwardRef(
|
|
|
509
498
|
collisionPadding,
|
|
510
499
|
sticky,
|
|
511
500
|
hideWhenDetached,
|
|
512
|
-
onInteractOutside: (e) => {
|
|
513
|
-
if (e.target === triggerRef.current) {
|
|
514
|
-
e.preventDefault();
|
|
515
|
-
}
|
|
516
|
-
onInteractOutside == null ? void 0 : onInteractOutside(e);
|
|
517
|
-
},
|
|
518
501
|
children: /* @__PURE__ */ jsx(
|
|
519
502
|
ScrollableContent,
|
|
520
503
|
{
|
|
@@ -720,49 +703,37 @@ const StyledTrigger = styled(RadixDropdownMenu.Trigger, {
|
|
|
720
703
|
}
|
|
721
704
|
});
|
|
722
705
|
|
|
723
|
-
const Trigger = React.forwardRef(({ asChild = false, ...restProps }, forwardRef) => {
|
|
706
|
+
const Trigger = React.forwardRef(({ asChild = false, onClick, ...restProps }, forwardRef) => {
|
|
724
707
|
const ref = useRef(null);
|
|
725
|
-
const
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
708
|
+
const handleVirtualClick = (e) => {
|
|
709
|
+
var _a;
|
|
710
|
+
if ((e == null ? void 0 : e.nativeEvent) === void 0) {
|
|
711
|
+
console.error(
|
|
712
|
+
"DropdownMenu.Trigger onClick expected a MouseEvent but got different one. It usually happens due to a element used asChild with a different onClick interface.\n" + "Event: ".concat(JSON.stringify(e, null, 2))
|
|
713
|
+
);
|
|
714
|
+
return;
|
|
731
715
|
}
|
|
732
|
-
|
|
733
|
-
|
|
716
|
+
const nativeEvent = e.nativeEvent;
|
|
717
|
+
if (nativeEvent.mozInputSource === void 0) {
|
|
718
|
+
nativeEvent.mozInputSource = null;
|
|
719
|
+
}
|
|
720
|
+
if (isVirtualClick(e.nativeEvent) && ref.current !== null) {
|
|
721
|
+
const pointerDownEvent = new MouseEvent("pointerdown", {
|
|
722
|
+
bubbles: true,
|
|
723
|
+
cancelable: true
|
|
724
|
+
});
|
|
725
|
+
(_a = ref.current) == null ? void 0 : _a.dispatchEvent(pointerDownEvent);
|
|
726
|
+
}
|
|
727
|
+
};
|
|
734
728
|
return /* @__PURE__ */ jsx(
|
|
735
729
|
StyledTrigger,
|
|
736
730
|
{
|
|
737
|
-
...
|
|
738
|
-
onPointerDown: (e) => {
|
|
739
|
-
var _a, _b;
|
|
740
|
-
if (process.env.NODE_ENV === "test") {
|
|
741
|
-
e.preventDefault = () => null;
|
|
742
|
-
(_a = restProps.onPointerDown) == null ? void 0 : _a.call(restProps, e);
|
|
743
|
-
return;
|
|
744
|
-
}
|
|
745
|
-
(_b = elementProps.onPointerDown) == null ? void 0 : _b.call(elementProps, e);
|
|
746
|
-
},
|
|
731
|
+
...restProps,
|
|
747
732
|
onClick: (e) => {
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
console.error(
|
|
751
|
-
"DropdownMenu.Trigger onClick expected a MouseEvent but got different one. It usually happens due to a element used asChild with a different onClick interface.\n" + "Event: ".concat(JSON.stringify(e, null, 2))
|
|
752
|
-
);
|
|
753
|
-
(_a = restProps.onClick) == null ? void 0 : _a.call(restProps, e);
|
|
754
|
-
return;
|
|
755
|
-
}
|
|
756
|
-
(_b = elementProps.onClick) == null ? void 0 : _b.call(elementProps, e);
|
|
733
|
+
handleVirtualClick(e);
|
|
734
|
+
onClick == null ? void 0 : onClick(e);
|
|
757
735
|
},
|
|
758
|
-
|
|
759
|
-
var _a;
|
|
760
|
-
if (!/^(Arrow|Tab|Escape)/.test(e.key)) {
|
|
761
|
-
e.preventDefault();
|
|
762
|
-
}
|
|
763
|
-
(_a = elementProps.onKeyDown) == null ? void 0 : _a.call(elementProps, e);
|
|
764
|
-
},
|
|
765
|
-
ref: mergeRefs([ref, triggerRef, forwardRef]),
|
|
736
|
+
ref: mergeRefs([ref, forwardRef]),
|
|
766
737
|
unstyled: !asChild,
|
|
767
738
|
asChild
|
|
768
739
|
}
|
|
@@ -913,52 +884,39 @@ const Root = ({
|
|
|
913
884
|
defaultOpen = false,
|
|
914
885
|
direction,
|
|
915
886
|
interactOutside = false,
|
|
887
|
+
open,
|
|
916
888
|
onOpen,
|
|
917
889
|
onClose,
|
|
918
890
|
...restProps
|
|
919
891
|
}) => {
|
|
920
892
|
const { ignoreNextTooltip } = useBaseTooltipContext();
|
|
921
|
-
const { rootOpen, open, setOpen } = useDropdownContext();
|
|
922
893
|
const prevOpen = usePrevious(open);
|
|
923
894
|
useEffect(() => {
|
|
924
|
-
if (prevOpen
|
|
925
|
-
|
|
926
|
-
onOpen == null ? void 0 : onOpen();
|
|
927
|
-
} else {
|
|
928
|
-
if (prevOpen === true) {
|
|
929
|
-
ignoreNextTooltip();
|
|
930
|
-
}
|
|
931
|
-
onClose == null ? void 0 : onClose();
|
|
932
|
-
}
|
|
895
|
+
if (prevOpen === true && open === false) {
|
|
896
|
+
ignoreNextTooltip();
|
|
933
897
|
}
|
|
934
|
-
}, [open, prevOpen
|
|
898
|
+
}, [ignoreNextTooltip, open, prevOpen]);
|
|
935
899
|
return /* @__PURE__ */ jsx(
|
|
936
900
|
RadixDropdownMenu.Root,
|
|
937
901
|
{
|
|
938
902
|
...restProps,
|
|
939
903
|
dir: direction,
|
|
940
904
|
modal: interactOutside,
|
|
941
|
-
open
|
|
942
|
-
// use the root open state if it is defined
|
|
943
|
-
rootOpen != null ? rootOpen : defaultOpen && (prevOpen === void 0 || prevOpen === open) ? (
|
|
944
|
-
// only use defaultOpen in the first render then use the context open state
|
|
945
|
-
// if the open state is the same as the previous one, it is most likely a re-render and we should still use the defaultOpen
|
|
946
|
-
void 0
|
|
947
|
-
) : (
|
|
948
|
-
// otherwise, use the user open state
|
|
949
|
-
open
|
|
950
|
-
)
|
|
951
|
-
),
|
|
905
|
+
open,
|
|
952
906
|
defaultOpen,
|
|
953
|
-
onOpenChange:
|
|
907
|
+
onOpenChange: (newOpen) => {
|
|
908
|
+
if (!newOpen && open === void 0) {
|
|
909
|
+
ignoreNextTooltip();
|
|
910
|
+
}
|
|
911
|
+
newOpen ? onOpen == null ? void 0 : onOpen() : onClose == null ? void 0 : onClose();
|
|
912
|
+
}
|
|
954
913
|
}
|
|
955
914
|
);
|
|
956
915
|
};
|
|
957
916
|
const DropdownMenu = ({
|
|
958
917
|
direction = "ltr",
|
|
959
|
-
open,
|
|
960
918
|
...restProps
|
|
961
|
-
}) => /* @__PURE__ */ jsx(DropdownProvider, { direction,
|
|
919
|
+
}) => /* @__PURE__ */ jsx(DropdownProvider, { direction, children: /* @__PURE__ */ jsx(BaseTooltipProvider, { children: /* @__PURE__ */ jsx(Root, { direction, ...restProps }) }) });
|
|
962
920
|
DropdownMenu.CheckboxItem = CheckboxItem;
|
|
963
921
|
DropdownMenu.Content = Content;
|
|
964
922
|
DropdownMenu.Hotkey = Hotkey;
|