@mirohq/design-system-dropdown-menu 4.4.9 → 4.4.10-dropdown-on-pointerup.1
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 +88 -46
- package/dist/main.js.map +1 -1
- package/dist/module.js +89 -47
- package/dist/module.js.map +1 -1
- package/package.json +8 -7
package/dist/module.js
CHANGED
|
@@ -14,7 +14,8 @@ 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 {
|
|
17
|
+
import { mergeProps } from '@react-aria/utils';
|
|
18
|
+
import { usePress } from '@mirohq/design-system-use-press';
|
|
18
19
|
import { styles as styles$1, isIconComponent } from '@mirohq/design-system-base-icon';
|
|
19
20
|
|
|
20
21
|
const ItemDescription = styled(Primitive.div, {
|
|
@@ -454,16 +455,25 @@ const ScrollableContent = ({
|
|
|
454
455
|
const DropdownContext = createContext({});
|
|
455
456
|
const DropdownProvider = ({
|
|
456
457
|
children,
|
|
458
|
+
open: rootOpen,
|
|
457
459
|
...restProps
|
|
458
|
-
}) =>
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
460
|
+
}) => {
|
|
461
|
+
const [open, setOpen] = useState(rootOpen);
|
|
462
|
+
const triggerRef = useRef(null);
|
|
463
|
+
return /* @__PURE__ */ jsx(
|
|
464
|
+
DropdownContext.Provider,
|
|
465
|
+
{
|
|
466
|
+
value: {
|
|
467
|
+
...restProps,
|
|
468
|
+
rootOpen,
|
|
469
|
+
open,
|
|
470
|
+
setOpen,
|
|
471
|
+
triggerRef
|
|
472
|
+
},
|
|
473
|
+
children
|
|
474
|
+
}
|
|
475
|
+
);
|
|
476
|
+
};
|
|
467
477
|
const useDropdownContext = () => useContext(DropdownContext);
|
|
468
478
|
|
|
469
479
|
const Content = React.forwardRef(
|
|
@@ -480,10 +490,11 @@ const Content = React.forwardRef(
|
|
|
480
490
|
containerSpacing = "medium",
|
|
481
491
|
overflow = "visible",
|
|
482
492
|
maxHeight,
|
|
493
|
+
onInteractOutside,
|
|
483
494
|
children,
|
|
484
495
|
...restProps
|
|
485
496
|
}, forwardRef) => {
|
|
486
|
-
const { direction } = useDropdownContext();
|
|
497
|
+
const { direction, triggerRef } = useDropdownContext();
|
|
487
498
|
return /* @__PURE__ */ jsx(ContentProvider, { containerSpacing, children: /* @__PURE__ */ jsx(
|
|
488
499
|
StyledContent,
|
|
489
500
|
{
|
|
@@ -498,6 +509,12 @@ const Content = React.forwardRef(
|
|
|
498
509
|
collisionPadding,
|
|
499
510
|
sticky,
|
|
500
511
|
hideWhenDetached,
|
|
512
|
+
onInteractOutside: (e) => {
|
|
513
|
+
if (e.target === triggerRef.current) {
|
|
514
|
+
e.preventDefault();
|
|
515
|
+
}
|
|
516
|
+
onInteractOutside == null ? void 0 : onInteractOutside(e);
|
|
517
|
+
},
|
|
501
518
|
children: /* @__PURE__ */ jsx(
|
|
502
519
|
ScrollableContent,
|
|
503
520
|
{
|
|
@@ -703,37 +720,49 @@ const StyledTrigger = styled(RadixDropdownMenu.Trigger, {
|
|
|
703
720
|
}
|
|
704
721
|
});
|
|
705
722
|
|
|
706
|
-
const Trigger = React.forwardRef(({ asChild = false,
|
|
723
|
+
const Trigger = React.forwardRef(({ asChild = false, ...restProps }, forwardRef) => {
|
|
707
724
|
const ref = useRef(null);
|
|
708
|
-
const
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
return;
|
|
715
|
-
}
|
|
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);
|
|
725
|
+
const { setOpen, rootOpen, triggerRef } = useDropdownContext();
|
|
726
|
+
const { pressProps } = usePress({
|
|
727
|
+
onPress: () => {
|
|
728
|
+
if (rootOpen === void 0) {
|
|
729
|
+
setOpen((open) => !booleanify(open));
|
|
730
|
+
}
|
|
726
731
|
}
|
|
727
|
-
};
|
|
732
|
+
});
|
|
733
|
+
const elementProps = mergeProps(restProps, pressProps);
|
|
728
734
|
return /* @__PURE__ */ jsx(
|
|
729
735
|
StyledTrigger,
|
|
730
736
|
{
|
|
731
|
-
...
|
|
737
|
+
...elementProps,
|
|
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
|
+
},
|
|
732
747
|
onClick: (e) => {
|
|
733
|
-
|
|
734
|
-
|
|
748
|
+
var _a, _b;
|
|
749
|
+
if ((e == null ? void 0 : e.nativeEvent) === void 0) {
|
|
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);
|
|
735
757
|
},
|
|
736
|
-
|
|
758
|
+
onKeyDown: (e) => {
|
|
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]),
|
|
737
766
|
unstyled: !asChild,
|
|
738
767
|
asChild
|
|
739
768
|
}
|
|
@@ -884,39 +913,52 @@ const Root = ({
|
|
|
884
913
|
defaultOpen = false,
|
|
885
914
|
direction,
|
|
886
915
|
interactOutside = false,
|
|
887
|
-
open,
|
|
888
916
|
onOpen,
|
|
889
917
|
onClose,
|
|
890
918
|
...restProps
|
|
891
919
|
}) => {
|
|
892
920
|
const { ignoreNextTooltip } = useBaseTooltipContext();
|
|
921
|
+
const { rootOpen, open, setOpen } = useDropdownContext();
|
|
893
922
|
const prevOpen = usePrevious(open);
|
|
894
923
|
useEffect(() => {
|
|
895
|
-
if (prevOpen
|
|
896
|
-
|
|
924
|
+
if (prevOpen !== open) {
|
|
925
|
+
if (open === true) {
|
|
926
|
+
onOpen == null ? void 0 : onOpen();
|
|
927
|
+
} else {
|
|
928
|
+
if (prevOpen === true) {
|
|
929
|
+
ignoreNextTooltip();
|
|
930
|
+
}
|
|
931
|
+
onClose == null ? void 0 : onClose();
|
|
932
|
+
}
|
|
897
933
|
}
|
|
898
|
-
}, [
|
|
934
|
+
}, [open, prevOpen, onOpen, onClose, ignoreNextTooltip]);
|
|
899
935
|
return /* @__PURE__ */ jsx(
|
|
900
936
|
RadixDropdownMenu.Root,
|
|
901
937
|
{
|
|
902
938
|
...restProps,
|
|
903
939
|
dir: direction,
|
|
904
940
|
modal: interactOutside,
|
|
905
|
-
open
|
|
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
|
+
),
|
|
906
952
|
defaultOpen,
|
|
907
|
-
onOpenChange:
|
|
908
|
-
if (!newOpen && open === void 0) {
|
|
909
|
-
ignoreNextTooltip();
|
|
910
|
-
}
|
|
911
|
-
newOpen ? onOpen == null ? void 0 : onOpen() : onClose == null ? void 0 : onClose();
|
|
912
|
-
}
|
|
953
|
+
onOpenChange: setOpen
|
|
913
954
|
}
|
|
914
955
|
);
|
|
915
956
|
};
|
|
916
957
|
const DropdownMenu = ({
|
|
917
958
|
direction = "ltr",
|
|
959
|
+
open,
|
|
918
960
|
...restProps
|
|
919
|
-
}) => /* @__PURE__ */ jsx(DropdownProvider, { direction, children: /* @__PURE__ */ jsx(BaseTooltipProvider, { children: /* @__PURE__ */ jsx(Root, { direction, ...restProps }) }) });
|
|
961
|
+
}) => /* @__PURE__ */ jsx(DropdownProvider, { direction, open, children: /* @__PURE__ */ jsx(BaseTooltipProvider, { children: /* @__PURE__ */ jsx(Root, { direction, ...restProps }) }) });
|
|
920
962
|
DropdownMenu.CheckboxItem = CheckboxItem;
|
|
921
963
|
DropdownMenu.Content = Content;
|
|
922
964
|
DropdownMenu.Hotkey = Hotkey;
|