@mirohq/design-system-dropdown-menu 4.4.9 → 4.4.10-dropdown-on-pointerup.0

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,6 +18,7 @@ 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');
21
22
  var designSystemBaseIcon = require('@mirohq/design-system-base-icon');
22
23
 
23
24
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -480,16 +481,25 @@ const ScrollableContent = ({
480
481
  const DropdownContext = React.createContext({});
481
482
  const DropdownProvider = ({
482
483
  children,
484
+ open: rootOpen,
483
485
  ...restProps
484
- }) => /* @__PURE__ */ jsxRuntime.jsx(
485
- DropdownContext.Provider,
486
- {
487
- value: {
488
- ...restProps
489
- },
490
- children
491
- }
492
- );
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
+ };
493
503
  const useDropdownContext = () => React.useContext(DropdownContext);
494
504
 
495
505
  const Content = React__default["default"].forwardRef(
@@ -506,10 +516,11 @@ const Content = React__default["default"].forwardRef(
506
516
  containerSpacing = "medium",
507
517
  overflow = "visible",
508
518
  maxHeight,
519
+ onInteractOutside,
509
520
  children,
510
521
  ...restProps
511
522
  }, forwardRef) => {
512
- const { direction } = useDropdownContext();
523
+ const { direction, triggerRef } = useDropdownContext();
513
524
  return /* @__PURE__ */ jsxRuntime.jsx(ContentProvider, { containerSpacing, children: /* @__PURE__ */ jsxRuntime.jsx(
514
525
  StyledContent,
515
526
  {
@@ -524,6 +535,12 @@ const Content = React__default["default"].forwardRef(
524
535
  collisionPadding,
525
536
  sticky,
526
537
  hideWhenDetached,
538
+ onInteractOutside: (e) => {
539
+ if (e.target === triggerRef.current) {
540
+ e.preventDefault();
541
+ }
542
+ onInteractOutside == null ? void 0 : onInteractOutside(e);
543
+ },
527
544
  children: /* @__PURE__ */ jsxRuntime.jsx(
528
545
  ScrollableContent,
529
546
  {
@@ -729,8 +746,9 @@ const StyledTrigger = designSystemStitches.styled(RadixDropdownMenu__namespace.T
729
746
  }
730
747
  });
731
748
 
732
- const Trigger = React__default["default"].forwardRef(({ asChild = false, onClick, ...restProps }, forwardRef) => {
749
+ const Trigger = React__default["default"].forwardRef(({ asChild = false, ...restProps }, forwardRef) => {
733
750
  const ref = React.useRef(null);
751
+ const { setOpen, rootOpen, triggerRef } = useDropdownContext();
734
752
  const handleVirtualClick = (e) => {
735
753
  var _a;
736
754
  if ((e == null ? void 0 : e.nativeEvent) === void 0) {
@@ -751,15 +769,40 @@ const Trigger = React__default["default"].forwardRef(({ asChild = false, onClick
751
769
  (_a = ref.current) == null ? void 0 : _a.dispatchEvent(pointerDownEvent);
752
770
  }
753
771
  };
772
+ const { pressProps } = designSystemUsePress.usePress({
773
+ onPress: () => {
774
+ if (rootOpen === void 0) {
775
+ setOpen((open) => !designSystemUtils.booleanify(open));
776
+ }
777
+ }
778
+ });
779
+ const elementProps = utils.mergeProps(restProps, pressProps);
754
780
  return /* @__PURE__ */ jsxRuntime.jsx(
755
781
  StyledTrigger,
756
782
  {
757
- ...restProps,
783
+ ...elementProps,
758
784
  onClick: (e) => {
785
+ var _a, _b;
759
786
  handleVirtualClick(e);
760
- onClick == null ? void 0 : onClick(e);
787
+ if (e instanceof MouseEvent) {
788
+ e.preventDefault();
789
+ (_a = elementProps.onClick) == null ? void 0 : _a.call(elementProps, e);
790
+ } else {
791
+ (_b = restProps.onClick) == null ? void 0 : _b.call(restProps, e);
792
+ }
761
793
  },
762
- ref: designSystemUtils.mergeRefs([ref, forwardRef]),
794
+ onKeyDown: (e) => {
795
+ var _a, _b;
796
+ if ((e == null ? void 0 : e.nativeEvent) instanceof KeyboardEvent) {
797
+ if (!/^(Arrow|Tab|Escape)/.test(e.key)) {
798
+ e.preventDefault();
799
+ }
800
+ (_a = elementProps.onKeyDown) == null ? void 0 : _a.call(elementProps, e);
801
+ } else {
802
+ (_b = restProps.onKeyDown) == null ? void 0 : _b.call(restProps, e);
803
+ }
804
+ },
805
+ ref: designSystemUtils.mergeRefs([ref, triggerRef, forwardRef]),
763
806
  unstyled: !asChild,
764
807
  asChild
765
808
  }
@@ -910,39 +953,52 @@ const Root = ({
910
953
  defaultOpen = false,
911
954
  direction,
912
955
  interactOutside = false,
913
- open,
914
956
  onOpen,
915
957
  onClose,
916
958
  ...restProps
917
959
  }) => {
918
960
  const { ignoreNextTooltip } = designSystemBaseTooltip.useBaseTooltipContext();
961
+ const { rootOpen, open, setOpen } = useDropdownContext();
919
962
  const prevOpen = designSystemUsePrevious.usePrevious(open);
920
963
  React.useEffect(() => {
921
- if (prevOpen === true && open === false) {
922
- ignoreNextTooltip();
964
+ if (prevOpen !== open) {
965
+ if (open === true) {
966
+ onOpen == null ? void 0 : onOpen();
967
+ } else {
968
+ if (prevOpen === true) {
969
+ ignoreNextTooltip();
970
+ }
971
+ onClose == null ? void 0 : onClose();
972
+ }
923
973
  }
924
- }, [ignoreNextTooltip, open, prevOpen]);
974
+ }, [open, prevOpen, onOpen, onClose, ignoreNextTooltip]);
925
975
  return /* @__PURE__ */ jsxRuntime.jsx(
926
976
  RadixDropdownMenu__namespace.Root,
927
977
  {
928
978
  ...restProps,
929
979
  dir: direction,
930
980
  modal: interactOutside,
931
- open,
981
+ open: (
982
+ // use the root open state if it is defined
983
+ rootOpen != null ? rootOpen : defaultOpen && (prevOpen === void 0 || prevOpen === open) ? (
984
+ // only use defaultOpen in the first render then use the context open state
985
+ // 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
986
+ void 0
987
+ ) : (
988
+ // otherwise, use the user open state
989
+ open
990
+ )
991
+ ),
932
992
  defaultOpen,
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
- }
993
+ onOpenChange: setOpen
939
994
  }
940
995
  );
941
996
  };
942
997
  const DropdownMenu = ({
943
998
  direction = "ltr",
999
+ open,
944
1000
  ...restProps
945
- }) => /* @__PURE__ */ jsxRuntime.jsx(DropdownProvider, { direction, children: /* @__PURE__ */ jsxRuntime.jsx(designSystemBaseTooltip.BaseTooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(Root, { direction, ...restProps }) }) });
1001
+ }) => /* @__PURE__ */ jsxRuntime.jsx(DropdownProvider, { direction, open, children: /* @__PURE__ */ jsxRuntime.jsx(designSystemBaseTooltip.BaseTooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(Root, { direction, ...restProps }) }) });
946
1002
  DropdownMenu.CheckboxItem = CheckboxItem;
947
1003
  DropdownMenu.Content = Content;
948
1004
  DropdownMenu.Hotkey = Hotkey;