@mirohq/design-system-dropdown-menu 4.4.10-dropdown-on-pointerup.2 → 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/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 { mergeProps } from '@react-aria/utils';
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
- 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
- };
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, triggerRef } = useDropdownContext();
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,51 +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 { setOpen, rootOpen, triggerRef } = useDropdownContext();
726
- const { pressProps } = usePress({
727
- onPress: () => {
728
- if (rootOpen === void 0) {
729
- setOpen((open) => !booleanify(open));
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
- const elementProps = mergeProps(restProps, pressProps);
734
- const onClickHandler = useCallback(
735
- (e) => {
736
- var _a, _b;
737
- if ((e == null ? void 0 : e.nativeEvent) === void 0) {
738
- console.error(
739
- "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))
740
- );
741
- (_a = restProps.onClick) == null ? void 0 : _a.call(restProps, e);
742
- return;
743
- }
744
- (_b = elementProps.onClick) == null ? void 0 : _b.call(elementProps, e);
745
- },
746
- [restProps, elementProps]
747
- );
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
+ };
748
728
  return /* @__PURE__ */ jsx(
749
729
  StyledTrigger,
750
730
  {
751
- ...elementProps,
752
- onPointerDown: (e) => {
753
- var _a;
754
- if (process.env.NODE_ENV === "test") {
755
- onClickHandler(e);
756
- }
757
- (_a = elementProps.onPointerDown) == null ? void 0 : _a.call(elementProps, e);
758
- },
759
- onClick: onClickHandler,
760
- onKeyDown: (e) => {
761
- var _a;
762
- if (!/^(Arrow|Tab|Escape)/.test(e.key)) {
763
- e.preventDefault();
764
- }
765
- (_a = elementProps.onKeyDown) == null ? void 0 : _a.call(elementProps, e);
731
+ ...restProps,
732
+ onClick: (e) => {
733
+ handleVirtualClick(e);
734
+ onClick == null ? void 0 : onClick(e);
766
735
  },
767
- ref: mergeRefs([ref, triggerRef, forwardRef]),
736
+ ref: mergeRefs([ref, forwardRef]),
768
737
  unstyled: !asChild,
769
738
  asChild
770
739
  }
@@ -915,52 +884,39 @@ const Root = ({
915
884
  defaultOpen = false,
916
885
  direction,
917
886
  interactOutside = false,
887
+ open,
918
888
  onOpen,
919
889
  onClose,
920
890
  ...restProps
921
891
  }) => {
922
892
  const { ignoreNextTooltip } = useBaseTooltipContext();
923
- const { rootOpen, open, setOpen } = useDropdownContext();
924
893
  const prevOpen = usePrevious(open);
925
894
  useEffect(() => {
926
- if (prevOpen !== open) {
927
- if (open === true) {
928
- onOpen == null ? void 0 : onOpen();
929
- } else {
930
- if (prevOpen === true) {
931
- ignoreNextTooltip();
932
- }
933
- onClose == null ? void 0 : onClose();
934
- }
895
+ if (prevOpen === true && open === false) {
896
+ ignoreNextTooltip();
935
897
  }
936
- }, [open, prevOpen, onOpen, onClose, ignoreNextTooltip]);
898
+ }, [ignoreNextTooltip, open, prevOpen]);
937
899
  return /* @__PURE__ */ jsx(
938
900
  RadixDropdownMenu.Root,
939
901
  {
940
902
  ...restProps,
941
903
  dir: direction,
942
904
  modal: interactOutside,
943
- open: (
944
- // use the root open state if it is defined
945
- rootOpen != null ? rootOpen : defaultOpen && (prevOpen === void 0 || prevOpen === open) ? (
946
- // only use defaultOpen in the first render then use the context open state
947
- // 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
948
- void 0
949
- ) : (
950
- // otherwise, use the user open state
951
- open
952
- )
953
- ),
905
+ open,
954
906
  defaultOpen,
955
- onOpenChange: setOpen
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
+ }
956
913
  }
957
914
  );
958
915
  };
959
916
  const DropdownMenu = ({
960
917
  direction = "ltr",
961
- open,
962
918
  ...restProps
963
- }) => /* @__PURE__ */ jsx(DropdownProvider, { direction, open, children: /* @__PURE__ */ jsx(BaseTooltipProvider, { children: /* @__PURE__ */ jsx(Root, { direction, ...restProps }) }) });
919
+ }) => /* @__PURE__ */ jsx(DropdownProvider, { direction, children: /* @__PURE__ */ jsx(BaseTooltipProvider, { children: /* @__PURE__ */ jsx(Root, { direction, ...restProps }) }) });
964
920
  DropdownMenu.CheckboxItem = CheckboxItem;
965
921
  DropdownMenu.Content = Content;
966
922
  DropdownMenu.Hotkey = Hotkey;