@mirohq/design-system-dropdown-menu 5.3.2-dropdown-on-pointerup.3 → 5.3.2
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 +28 -92
- package/dist/main.js.map +1 -1
- package/dist/module.js +29 -93
- package/dist/module.js.map +1 -1
- package/package.json +7 -9
package/dist/module.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Portal as Portal$1 } from '@radix-ui/react-dropdown-menu';
|
|
|
5
5
|
import { BaseTooltipProvider, useBaseTooltipContext } from '@mirohq/design-system-base-tooltip';
|
|
6
6
|
import { usePrevious } from '@mirohq/design-system-use-previous';
|
|
7
7
|
import { IconProhibit, IconCheckMark, IconMinus, IconChevronRight } from '@mirohq/design-system-icons';
|
|
8
|
-
import { addPropsToChildren, booleanify, mergeRefs } from '@mirohq/design-system-utils';
|
|
8
|
+
import { addPropsToChildren, booleanify, mergeRefs, handleVirtualClick } from '@mirohq/design-system-utils';
|
|
9
9
|
import { Primitive } from '@mirohq/design-system-primitive';
|
|
10
10
|
import { styled, theme } from '@mirohq/design-system-stitches';
|
|
11
11
|
import { focus, animations } from '@mirohq/design-system-styles';
|
|
@@ -14,8 +14,6 @@ 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 { mergeProps } from '@react-aria/utils';
|
|
18
|
-
import { usePress } from '@mirohq/design-system-use-press';
|
|
19
17
|
import { styles as styles$1, isIconComponent } from '@mirohq/design-system-base-icon';
|
|
20
18
|
|
|
21
19
|
const Context$1 = createContext({
|
|
@@ -461,25 +459,16 @@ const ScrollableContent = ({
|
|
|
461
459
|
const DropdownContext = createContext({});
|
|
462
460
|
const DropdownProvider = ({
|
|
463
461
|
children,
|
|
464
|
-
open: rootOpen,
|
|
465
462
|
...restProps
|
|
466
|
-
}) =>
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
open,
|
|
476
|
-
setOpen,
|
|
477
|
-
triggerRef
|
|
478
|
-
},
|
|
479
|
-
children
|
|
480
|
-
}
|
|
481
|
-
);
|
|
482
|
-
};
|
|
463
|
+
}) => /* @__PURE__ */ jsx(
|
|
464
|
+
DropdownContext.Provider,
|
|
465
|
+
{
|
|
466
|
+
value: {
|
|
467
|
+
...restProps
|
|
468
|
+
},
|
|
469
|
+
children
|
|
470
|
+
}
|
|
471
|
+
);
|
|
483
472
|
const useDropdownContext = () => useContext(DropdownContext);
|
|
484
473
|
|
|
485
474
|
const Content = React.forwardRef(
|
|
@@ -496,11 +485,10 @@ const Content = React.forwardRef(
|
|
|
496
485
|
containerSpacing = "medium",
|
|
497
486
|
overflow = "visible",
|
|
498
487
|
maxHeight,
|
|
499
|
-
onInteractOutside,
|
|
500
488
|
children,
|
|
501
489
|
...restProps
|
|
502
490
|
}, forwardRef) => {
|
|
503
|
-
const { direction
|
|
491
|
+
const { direction } = useDropdownContext();
|
|
504
492
|
const preventScrollOnFocus = (ref) => {
|
|
505
493
|
if (ref === null || "_autoScrollPrevented" in ref.focus) {
|
|
506
494
|
return;
|
|
@@ -533,12 +521,6 @@ const Content = React.forwardRef(
|
|
|
533
521
|
collisionPadding,
|
|
534
522
|
sticky,
|
|
535
523
|
hideWhenDetached,
|
|
536
|
-
onInteractOutside: (e) => {
|
|
537
|
-
if (e.target === triggerRef.current) {
|
|
538
|
-
e.preventDefault();
|
|
539
|
-
}
|
|
540
|
-
onInteractOutside == null ? void 0 : onInteractOutside(e);
|
|
541
|
-
},
|
|
542
524
|
children: /* @__PURE__ */ jsx(
|
|
543
525
|
ScrollableContent,
|
|
544
526
|
{
|
|
@@ -744,51 +726,17 @@ const StyledTrigger = styled(RadixDropdownMenu.Trigger, {
|
|
|
744
726
|
}
|
|
745
727
|
});
|
|
746
728
|
|
|
747
|
-
const Trigger = React.forwardRef(({ asChild = false, ...restProps }, forwardRef) => {
|
|
729
|
+
const Trigger = React.forwardRef(({ asChild = false, onClick, ...restProps }, forwardRef) => {
|
|
748
730
|
const ref = useRef(null);
|
|
749
|
-
const { setOpen, rootOpen, triggerRef } = useDropdownContext();
|
|
750
|
-
const { pressProps } = usePress({
|
|
751
|
-
onPress: () => {
|
|
752
|
-
if (rootOpen === void 0) {
|
|
753
|
-
setOpen((open) => !booleanify(open));
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
});
|
|
757
|
-
const elementProps = mergeProps(restProps, pressProps);
|
|
758
|
-
const onClickHandler = useCallback(
|
|
759
|
-
(e) => {
|
|
760
|
-
var _a, _b;
|
|
761
|
-
if ((e == null ? void 0 : e.nativeEvent) === void 0) {
|
|
762
|
-
console.error(
|
|
763
|
-
"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))
|
|
764
|
-
);
|
|
765
|
-
(_a = restProps.onClick) == null ? void 0 : _a.call(restProps, e);
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
|
-
(_b = elementProps.onClick) == null ? void 0 : _b.call(elementProps, e);
|
|
769
|
-
},
|
|
770
|
-
[restProps, elementProps]
|
|
771
|
-
);
|
|
772
731
|
return /* @__PURE__ */ jsx(
|
|
773
732
|
StyledTrigger,
|
|
774
733
|
{
|
|
775
|
-
...
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
onClickHandler(e);
|
|
780
|
-
}
|
|
781
|
-
(_a = elementProps.onPointerDown) == null ? void 0 : _a.call(elementProps, e);
|
|
782
|
-
},
|
|
783
|
-
onClick: onClickHandler,
|
|
784
|
-
onKeyDown: (e) => {
|
|
785
|
-
var _a;
|
|
786
|
-
if (!/^(Arrow|Tab|Escape)/.test(e.key)) {
|
|
787
|
-
e.preventDefault();
|
|
788
|
-
}
|
|
789
|
-
(_a = elementProps.onKeyDown) == null ? void 0 : _a.call(elementProps, e);
|
|
734
|
+
...restProps,
|
|
735
|
+
onClick: (e) => {
|
|
736
|
+
handleVirtualClick(e, ref);
|
|
737
|
+
onClick == null ? void 0 : onClick(e);
|
|
790
738
|
},
|
|
791
|
-
ref: mergeRefs([ref,
|
|
739
|
+
ref: mergeRefs([ref, forwardRef]),
|
|
792
740
|
unstyled: !asChild,
|
|
793
741
|
asChild
|
|
794
742
|
}
|
|
@@ -943,48 +891,36 @@ const Root = ({
|
|
|
943
891
|
defaultOpen = false,
|
|
944
892
|
direction,
|
|
945
893
|
interactOutside = false,
|
|
894
|
+
open,
|
|
946
895
|
onOpen,
|
|
947
896
|
onClose,
|
|
948
897
|
...restProps
|
|
949
898
|
}) => {
|
|
950
899
|
const { ignoreNextTooltip } = useBaseTooltipContext();
|
|
951
|
-
const { rootOpen, open, setOpen } = useDropdownContext();
|
|
952
900
|
const prevOpen = usePrevious(open);
|
|
953
901
|
useEffect(() => {
|
|
954
|
-
if (prevOpen
|
|
955
|
-
|
|
956
|
-
onOpen == null ? void 0 : onOpen();
|
|
957
|
-
} else {
|
|
958
|
-
if (prevOpen === true) {
|
|
959
|
-
ignoreNextTooltip();
|
|
960
|
-
}
|
|
961
|
-
onClose == null ? void 0 : onClose();
|
|
962
|
-
}
|
|
902
|
+
if (prevOpen === true && open === false) {
|
|
903
|
+
ignoreNextTooltip();
|
|
963
904
|
}
|
|
964
|
-
}, [open, prevOpen
|
|
905
|
+
}, [ignoreNextTooltip, open, prevOpen]);
|
|
965
906
|
return /* @__PURE__ */ jsx(
|
|
966
907
|
RadixDropdownMenu.Root,
|
|
967
908
|
{
|
|
968
909
|
...restProps,
|
|
969
910
|
dir: direction,
|
|
970
911
|
modal: interactOutside,
|
|
971
|
-
open
|
|
972
|
-
// use the root open state if it is defined
|
|
973
|
-
rootOpen != null ? rootOpen : defaultOpen && (prevOpen === void 0 || prevOpen === open) ? (
|
|
974
|
-
// only use defaultOpen in the first render then use the context open state
|
|
975
|
-
// 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
|
|
976
|
-
void 0
|
|
977
|
-
) : (
|
|
978
|
-
// otherwise, use the user open state
|
|
979
|
-
open
|
|
980
|
-
)
|
|
981
|
-
),
|
|
912
|
+
open,
|
|
982
913
|
defaultOpen,
|
|
983
|
-
onOpenChange:
|
|
914
|
+
onOpenChange: (newOpen) => {
|
|
915
|
+
if (!newOpen && open === void 0) {
|
|
916
|
+
ignoreNextTooltip();
|
|
917
|
+
}
|
|
918
|
+
newOpen ? onOpen == null ? void 0 : onOpen() : onClose == null ? void 0 : onClose();
|
|
919
|
+
}
|
|
984
920
|
}
|
|
985
921
|
);
|
|
986
922
|
};
|
|
987
|
-
const DropdownMenu = ({ direction = "ltr",
|
|
923
|
+
const DropdownMenu = ({ direction = "ltr", ...restProps }) => /* @__PURE__ */ jsx(DropdownProvider, { direction, children: /* @__PURE__ */ jsx(BaseTooltipProvider, { children: /* @__PURE__ */ jsx(Root, { direction, ...restProps }) }) });
|
|
988
924
|
DropdownMenu.CheckboxItem = CheckboxItem;
|
|
989
925
|
DropdownMenu.Content = Content;
|
|
990
926
|
DropdownMenu.Hotkey = Hotkey;
|