@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 CHANGED
@@ -18,7 +18,6 @@ var designSystemUseAriaDisabled = require('@mirohq/design-system-use-aria-disabl
18
18
  var designSystemScrollArea = require('@mirohq/design-system-scroll-area');
19
19
  var designSystemBaseSwitch = require('@mirohq/design-system-base-switch');
20
20
  var utils = require('@react-aria/utils');
21
- var designSystemUsePress = require('@mirohq/design-system-use-press');
22
21
  var designSystemBaseIcon = require('@mirohq/design-system-base-icon');
23
22
 
24
23
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -481,25 +480,16 @@ const ScrollableContent = ({
481
480
  const DropdownContext = React.createContext({});
482
481
  const DropdownProvider = ({
483
482
  children,
484
- open: rootOpen,
485
483
  ...restProps
486
- }) => {
487
- const [open, setOpen] = React.useState(rootOpen);
488
- const triggerRef = React.useRef(null);
489
- return /* @__PURE__ */ jsxRuntime.jsx(
490
- DropdownContext.Provider,
491
- {
492
- value: {
493
- ...restProps,
494
- rootOpen,
495
- open,
496
- setOpen,
497
- triggerRef
498
- },
499
- children
500
- }
501
- );
502
- };
484
+ }) => /* @__PURE__ */ jsxRuntime.jsx(
485
+ DropdownContext.Provider,
486
+ {
487
+ value: {
488
+ ...restProps
489
+ },
490
+ children
491
+ }
492
+ );
503
493
  const useDropdownContext = () => React.useContext(DropdownContext);
504
494
 
505
495
  const Content = React__default["default"].forwardRef(
@@ -516,11 +506,10 @@ const Content = React__default["default"].forwardRef(
516
506
  containerSpacing = "medium",
517
507
  overflow = "visible",
518
508
  maxHeight,
519
- onInteractOutside,
520
509
  children,
521
510
  ...restProps
522
511
  }, forwardRef) => {
523
- const { direction, triggerRef } = useDropdownContext();
512
+ const { direction } = useDropdownContext();
524
513
  return /* @__PURE__ */ jsxRuntime.jsx(ContentProvider, { containerSpacing, children: /* @__PURE__ */ jsxRuntime.jsx(
525
514
  StyledContent,
526
515
  {
@@ -535,12 +524,6 @@ const Content = React__default["default"].forwardRef(
535
524
  collisionPadding,
536
525
  sticky,
537
526
  hideWhenDetached,
538
- onInteractOutside: (e) => {
539
- if (e.target === triggerRef.current) {
540
- e.preventDefault();
541
- }
542
- onInteractOutside == null ? void 0 : onInteractOutside(e);
543
- },
544
527
  children: /* @__PURE__ */ jsxRuntime.jsx(
545
528
  ScrollableContent,
546
529
  {
@@ -746,49 +729,37 @@ const StyledTrigger = designSystemStitches.styled(RadixDropdownMenu__namespace.T
746
729
  }
747
730
  });
748
731
 
749
- const Trigger = React__default["default"].forwardRef(({ asChild = false, ...restProps }, forwardRef) => {
732
+ const Trigger = React__default["default"].forwardRef(({ asChild = false, onClick, ...restProps }, forwardRef) => {
750
733
  const ref = React.useRef(null);
751
- const { setOpen, rootOpen, triggerRef } = useDropdownContext();
752
- const { pressProps } = designSystemUsePress.usePress({
753
- onPress: () => {
754
- if (rootOpen === void 0) {
755
- setOpen((open) => !designSystemUtils.booleanify(open));
756
- }
734
+ const handleVirtualClick = (e) => {
735
+ var _a;
736
+ if ((e == null ? void 0 : e.nativeEvent) === void 0) {
737
+ console.error(
738
+ "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))
739
+ );
740
+ return;
757
741
  }
758
- });
759
- const elementProps = utils.mergeProps(restProps, pressProps);
742
+ const nativeEvent = e.nativeEvent;
743
+ if (nativeEvent.mozInputSource === void 0) {
744
+ nativeEvent.mozInputSource = null;
745
+ }
746
+ if (utils.isVirtualClick(e.nativeEvent) && ref.current !== null) {
747
+ const pointerDownEvent = new MouseEvent("pointerdown", {
748
+ bubbles: true,
749
+ cancelable: true
750
+ });
751
+ (_a = ref.current) == null ? void 0 : _a.dispatchEvent(pointerDownEvent);
752
+ }
753
+ };
760
754
  return /* @__PURE__ */ jsxRuntime.jsx(
761
755
  StyledTrigger,
762
756
  {
763
- ...elementProps,
764
- onPointerDown: (e) => {
765
- var _a, _b;
766
- if (process.env.NODE_ENV === "test") {
767
- e.preventDefault = () => null;
768
- (_a = restProps.onPointerDown) == null ? void 0 : _a.call(restProps, e);
769
- return;
770
- }
771
- (_b = elementProps.onPointerDown) == null ? void 0 : _b.call(elementProps, e);
772
- },
757
+ ...restProps,
773
758
  onClick: (e) => {
774
- var _a, _b;
775
- if ((e == null ? void 0 : e.nativeEvent) === void 0) {
776
- console.error(
777
- "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))
778
- );
779
- (_a = restProps.onClick) == null ? void 0 : _a.call(restProps, e);
780
- return;
781
- }
782
- (_b = elementProps.onClick) == null ? void 0 : _b.call(elementProps, e);
759
+ handleVirtualClick(e);
760
+ onClick == null ? void 0 : onClick(e);
783
761
  },
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);
790
- },
791
- ref: designSystemUtils.mergeRefs([ref, triggerRef, forwardRef]),
762
+ ref: designSystemUtils.mergeRefs([ref, forwardRef]),
792
763
  unstyled: !asChild,
793
764
  asChild
794
765
  }
@@ -939,52 +910,39 @@ const Root = ({
939
910
  defaultOpen = false,
940
911
  direction,
941
912
  interactOutside = false,
913
+ open,
942
914
  onOpen,
943
915
  onClose,
944
916
  ...restProps
945
917
  }) => {
946
918
  const { ignoreNextTooltip } = designSystemBaseTooltip.useBaseTooltipContext();
947
- const { rootOpen, open, setOpen } = useDropdownContext();
948
919
  const prevOpen = designSystemUsePrevious.usePrevious(open);
949
920
  React.useEffect(() => {
950
- if (prevOpen !== open) {
951
- if (open === true) {
952
- onOpen == null ? void 0 : onOpen();
953
- } else {
954
- if (prevOpen === true) {
955
- ignoreNextTooltip();
956
- }
957
- onClose == null ? void 0 : onClose();
958
- }
921
+ if (prevOpen === true && open === false) {
922
+ ignoreNextTooltip();
959
923
  }
960
- }, [open, prevOpen, onOpen, onClose, ignoreNextTooltip]);
924
+ }, [ignoreNextTooltip, open, prevOpen]);
961
925
  return /* @__PURE__ */ jsxRuntime.jsx(
962
926
  RadixDropdownMenu__namespace.Root,
963
927
  {
964
928
  ...restProps,
965
929
  dir: direction,
966
930
  modal: interactOutside,
967
- open: (
968
- // use the root open state if it is defined
969
- rootOpen != null ? rootOpen : defaultOpen && (prevOpen === void 0 || prevOpen === open) ? (
970
- // only use defaultOpen in the first render then use the context open state
971
- // 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
972
- void 0
973
- ) : (
974
- // otherwise, use the user open state
975
- open
976
- )
977
- ),
931
+ open,
978
932
  defaultOpen,
979
- onOpenChange: setOpen
933
+ onOpenChange: (newOpen) => {
934
+ if (!newOpen && open === void 0) {
935
+ ignoreNextTooltip();
936
+ }
937
+ newOpen ? onOpen == null ? void 0 : onOpen() : onClose == null ? void 0 : onClose();
938
+ }
980
939
  }
981
940
  );
982
941
  };
983
942
  const DropdownMenu = ({
984
943
  direction = "ltr",
985
- open,
986
944
  ...restProps
987
- }) => /* @__PURE__ */ jsxRuntime.jsx(DropdownProvider, { direction, open, children: /* @__PURE__ */ jsxRuntime.jsx(designSystemBaseTooltip.BaseTooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(Root, { direction, ...restProps }) }) });
945
+ }) => /* @__PURE__ */ jsxRuntime.jsx(DropdownProvider, { direction, children: /* @__PURE__ */ jsxRuntime.jsx(designSystemBaseTooltip.BaseTooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(Root, { direction, ...restProps }) }) });
988
946
  DropdownMenu.CheckboxItem = CheckboxItem;
989
947
  DropdownMenu.Content = Content;
990
948
  DropdownMenu.Hotkey = Hotkey;