@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 CHANGED
@@ -15,8 +15,6 @@ var designSystemUseLayoutEffect = require('@mirohq/design-system-use-layout-effe
15
15
  var designSystemUseAriaDisabled = require('@mirohq/design-system-use-aria-disabled');
16
16
  var designSystemScrollArea = require('@mirohq/design-system-scroll-area');
17
17
  var designSystemBaseSwitch = require('@mirohq/design-system-base-switch');
18
- var utils = require('@react-aria/utils');
19
- var designSystemUsePress = require('@mirohq/design-system-use-press');
20
18
  var designSystemBaseIcon = require('@mirohq/design-system-base-icon');
21
19
 
22
20
  function _interopNamespaceDefault(e) {
@@ -481,25 +479,16 @@ const ScrollableContent = ({
481
479
  const DropdownContext = React.createContext({});
482
480
  const DropdownProvider = ({
483
481
  children,
484
- open: rootOpen,
485
482
  ...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
- };
483
+ }) => /* @__PURE__ */ jsxRuntime.jsx(
484
+ DropdownContext.Provider,
485
+ {
486
+ value: {
487
+ ...restProps
488
+ },
489
+ children
490
+ }
491
+ );
503
492
  const useDropdownContext = () => React.useContext(DropdownContext);
504
493
 
505
494
  const Content = React.forwardRef(
@@ -516,11 +505,10 @@ const Content = React.forwardRef(
516
505
  containerSpacing = "medium",
517
506
  overflow = "visible",
518
507
  maxHeight,
519
- onInteractOutside,
520
508
  children,
521
509
  ...restProps
522
510
  }, forwardRef) => {
523
- const { direction, triggerRef } = useDropdownContext();
511
+ const { direction } = useDropdownContext();
524
512
  const preventScrollOnFocus = (ref) => {
525
513
  if (ref === null || "_autoScrollPrevented" in ref.focus) {
526
514
  return;
@@ -553,12 +541,6 @@ const Content = React.forwardRef(
553
541
  collisionPadding,
554
542
  sticky,
555
543
  hideWhenDetached,
556
- onInteractOutside: (e) => {
557
- if (e.target === triggerRef.current) {
558
- e.preventDefault();
559
- }
560
- onInteractOutside == null ? void 0 : onInteractOutside(e);
561
- },
562
544
  children: /* @__PURE__ */ jsxRuntime.jsx(
563
545
  ScrollableContent,
564
546
  {
@@ -764,51 +746,17 @@ const StyledTrigger = designSystemStitches.styled(RadixDropdownMenu__namespace.T
764
746
  }
765
747
  });
766
748
 
767
- const Trigger = React.forwardRef(({ asChild = false, ...restProps }, forwardRef) => {
749
+ const Trigger = React.forwardRef(({ asChild = false, onClick, ...restProps }, forwardRef) => {
768
750
  const ref = React.useRef(null);
769
- const { setOpen, rootOpen, triggerRef } = useDropdownContext();
770
- const { pressProps } = designSystemUsePress.usePress({
771
- onPress: () => {
772
- if (rootOpen === void 0) {
773
- setOpen((open) => !designSystemUtils.booleanify(open));
774
- }
775
- }
776
- });
777
- const elementProps = utils.mergeProps(restProps, pressProps);
778
- const onClickHandler = React.useCallback(
779
- (e) => {
780
- var _a, _b;
781
- if ((e == null ? void 0 : e.nativeEvent) === void 0) {
782
- console.error(
783
- "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))
784
- );
785
- (_a = restProps.onClick) == null ? void 0 : _a.call(restProps, e);
786
- return;
787
- }
788
- (_b = elementProps.onClick) == null ? void 0 : _b.call(elementProps, e);
789
- },
790
- [restProps, elementProps]
791
- );
792
751
  return /* @__PURE__ */ jsxRuntime.jsx(
793
752
  StyledTrigger,
794
753
  {
795
- ...elementProps,
796
- onPointerDown: (e) => {
797
- var _a;
798
- if (process.env.NODE_ENV === "test") {
799
- onClickHandler(e);
800
- }
801
- (_a = elementProps.onPointerDown) == null ? void 0 : _a.call(elementProps, e);
802
- },
803
- onClick: onClickHandler,
804
- onKeyDown: (e) => {
805
- var _a;
806
- if (!/^(Arrow|Tab|Escape)/.test(e.key)) {
807
- e.preventDefault();
808
- }
809
- (_a = elementProps.onKeyDown) == null ? void 0 : _a.call(elementProps, e);
754
+ ...restProps,
755
+ onClick: (e) => {
756
+ designSystemUtils.handleVirtualClick(e, ref);
757
+ onClick == null ? void 0 : onClick(e);
810
758
  },
811
- ref: designSystemUtils.mergeRefs([ref, triggerRef, forwardRef]),
759
+ ref: designSystemUtils.mergeRefs([ref, forwardRef]),
812
760
  unstyled: !asChild,
813
761
  asChild
814
762
  }
@@ -963,48 +911,36 @@ const Root = ({
963
911
  defaultOpen = false,
964
912
  direction,
965
913
  interactOutside = false,
914
+ open,
966
915
  onOpen,
967
916
  onClose,
968
917
  ...restProps
969
918
  }) => {
970
919
  const { ignoreNextTooltip } = designSystemBaseTooltip.useBaseTooltipContext();
971
- const { rootOpen, open, setOpen } = useDropdownContext();
972
920
  const prevOpen = designSystemUsePrevious.usePrevious(open);
973
921
  React.useEffect(() => {
974
- if (prevOpen !== open) {
975
- if (open === true) {
976
- onOpen == null ? void 0 : onOpen();
977
- } else {
978
- if (prevOpen === true) {
979
- ignoreNextTooltip();
980
- }
981
- onClose == null ? void 0 : onClose();
982
- }
922
+ if (prevOpen === true && open === false) {
923
+ ignoreNextTooltip();
983
924
  }
984
- }, [open, prevOpen, onOpen, onClose, ignoreNextTooltip]);
925
+ }, [ignoreNextTooltip, open, prevOpen]);
985
926
  return /* @__PURE__ */ jsxRuntime.jsx(
986
927
  RadixDropdownMenu__namespace.Root,
987
928
  {
988
929
  ...restProps,
989
930
  dir: direction,
990
931
  modal: interactOutside,
991
- open: (
992
- // use the root open state if it is defined
993
- rootOpen != null ? rootOpen : defaultOpen && (prevOpen === void 0 || prevOpen === open) ? (
994
- // only use defaultOpen in the first render then use the context open state
995
- // 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
996
- void 0
997
- ) : (
998
- // otherwise, use the user open state
999
- open
1000
- )
1001
- ),
932
+ open,
1002
933
  defaultOpen,
1003
- onOpenChange: setOpen
934
+ onOpenChange: (newOpen) => {
935
+ if (!newOpen && open === void 0) {
936
+ ignoreNextTooltip();
937
+ }
938
+ newOpen ? onOpen == null ? void 0 : onOpen() : onClose == null ? void 0 : onClose();
939
+ }
1004
940
  }
1005
941
  );
1006
942
  };
1007
- const DropdownMenu = ({ direction = "ltr", open, ...restProps }) => /* @__PURE__ */ jsxRuntime.jsx(DropdownProvider, { direction, open, children: /* @__PURE__ */ jsxRuntime.jsx(designSystemBaseTooltip.BaseTooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(Root, { direction, ...restProps }) }) });
943
+ const DropdownMenu = ({ direction = "ltr", ...restProps }) => /* @__PURE__ */ jsxRuntime.jsx(DropdownProvider, { direction, children: /* @__PURE__ */ jsxRuntime.jsx(designSystemBaseTooltip.BaseTooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(Root, { direction, ...restProps }) }) });
1008
944
  DropdownMenu.CheckboxItem = CheckboxItem;
1009
945
  DropdownMenu.Content = Content;
1010
946
  DropdownMenu.Hotkey = Hotkey;