@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/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,51 +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);
760
- const onClickHandler = React.useCallback(
761
- (e) => {
762
- var _a, _b;
763
- if ((e == null ? void 0 : e.nativeEvent) === void 0) {
764
- console.error(
765
- "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))
766
- );
767
- (_a = restProps.onClick) == null ? void 0 : _a.call(restProps, e);
768
- return;
769
- }
770
- (_b = elementProps.onClick) == null ? void 0 : _b.call(elementProps, e);
771
- },
772
- [restProps, elementProps]
773
- );
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
+ };
774
754
  return /* @__PURE__ */ jsxRuntime.jsx(
775
755
  StyledTrigger,
776
756
  {
777
- ...elementProps,
778
- onPointerDown: (e) => {
779
- var _a;
780
- if (process.env.NODE_ENV === "test") {
781
- onClickHandler(e);
782
- }
783
- (_a = elementProps.onPointerDown) == null ? void 0 : _a.call(elementProps, e);
784
- },
785
- onClick: onClickHandler,
786
- onKeyDown: (e) => {
787
- var _a;
788
- if (!/^(Arrow|Tab|Escape)/.test(e.key)) {
789
- e.preventDefault();
790
- }
791
- (_a = elementProps.onKeyDown) == null ? void 0 : _a.call(elementProps, e);
757
+ ...restProps,
758
+ onClick: (e) => {
759
+ handleVirtualClick(e);
760
+ onClick == null ? void 0 : onClick(e);
792
761
  },
793
- ref: designSystemUtils.mergeRefs([ref, triggerRef, forwardRef]),
762
+ ref: designSystemUtils.mergeRefs([ref, forwardRef]),
794
763
  unstyled: !asChild,
795
764
  asChild
796
765
  }
@@ -941,52 +910,39 @@ const Root = ({
941
910
  defaultOpen = false,
942
911
  direction,
943
912
  interactOutside = false,
913
+ open,
944
914
  onOpen,
945
915
  onClose,
946
916
  ...restProps
947
917
  }) => {
948
918
  const { ignoreNextTooltip } = designSystemBaseTooltip.useBaseTooltipContext();
949
- const { rootOpen, open, setOpen } = useDropdownContext();
950
919
  const prevOpen = designSystemUsePrevious.usePrevious(open);
951
920
  React.useEffect(() => {
952
- if (prevOpen !== open) {
953
- if (open === true) {
954
- onOpen == null ? void 0 : onOpen();
955
- } else {
956
- if (prevOpen === true) {
957
- ignoreNextTooltip();
958
- }
959
- onClose == null ? void 0 : onClose();
960
- }
921
+ if (prevOpen === true && open === false) {
922
+ ignoreNextTooltip();
961
923
  }
962
- }, [open, prevOpen, onOpen, onClose, ignoreNextTooltip]);
924
+ }, [ignoreNextTooltip, open, prevOpen]);
963
925
  return /* @__PURE__ */ jsxRuntime.jsx(
964
926
  RadixDropdownMenu__namespace.Root,
965
927
  {
966
928
  ...restProps,
967
929
  dir: direction,
968
930
  modal: interactOutside,
969
- open: (
970
- // use the root open state if it is defined
971
- rootOpen != null ? rootOpen : defaultOpen && (prevOpen === void 0 || prevOpen === open) ? (
972
- // only use defaultOpen in the first render then use the context open state
973
- // 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
974
- void 0
975
- ) : (
976
- // otherwise, use the user open state
977
- open
978
- )
979
- ),
931
+ open,
980
932
  defaultOpen,
981
- 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
+ }
982
939
  }
983
940
  );
984
941
  };
985
942
  const DropdownMenu = ({
986
943
  direction = "ltr",
987
- open,
988
944
  ...restProps
989
- }) => /* @__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 }) }) });
990
946
  DropdownMenu.CheckboxItem = CheckboxItem;
991
947
  DropdownMenu.Content = Content;
992
948
  DropdownMenu.Hotkey = Hotkey;