@mirohq/design-system-dropdown-menu 5.3.8-dropdown-close-on-mouseup.1 → 5.3.9

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,7 +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 designSystemUseEventListener = require('@mirohq/design-system-use-event-listener');
19
18
  var designSystemBaseIcon = require('@mirohq/design-system-base-icon');
20
19
 
21
20
  function _interopNamespaceDefault(e) {
@@ -480,28 +479,16 @@ const ScrollableContent = ({
480
479
  const DropdownContext = React.createContext({});
481
480
  const DropdownProvider = ({
482
481
  children,
483
- open: rootOpen,
484
482
  ...restProps
485
- }) => {
486
- const [open, setOpen] = React.useState(rootOpen);
487
- const triggerRef = React.useRef(null);
488
- React.useEffect(() => {
489
- setOpen(rootOpen);
490
- }, [rootOpen]);
491
- return /* @__PURE__ */ jsxRuntime.jsx(
492
- DropdownContext.Provider,
493
- {
494
- value: {
495
- ...restProps,
496
- open,
497
- setOpen,
498
- triggerRef,
499
- rootOpen
500
- },
501
- children
502
- }
503
- );
504
- };
483
+ }) => /* @__PURE__ */ jsxRuntime.jsx(
484
+ DropdownContext.Provider,
485
+ {
486
+ value: {
487
+ ...restProps
488
+ },
489
+ children
490
+ }
491
+ );
505
492
  const useDropdownContext = () => React.useContext(DropdownContext);
506
493
 
507
494
  const Content = React.forwardRef(
@@ -518,11 +505,10 @@ const Content = React.forwardRef(
518
505
  containerSpacing = "medium",
519
506
  overflow = "visible",
520
507
  maxHeight,
521
- onFocusOutside,
522
508
  children,
523
509
  ...restProps
524
510
  }, forwardRef) => {
525
- const { direction, rootOpen } = useDropdownContext();
511
+ const { direction } = useDropdownContext();
526
512
  const preventScrollOnFocus = (ref) => {
527
513
  if (ref === null || "_autoScrollPrevented" in ref.focus) {
528
514
  return;
@@ -541,12 +527,6 @@ const Content = React.forwardRef(
541
527
  focusWithouAutoScroll._autoScrollPrevented = true;
542
528
  ref.focus = focusWithouAutoScroll;
543
529
  };
544
- const handleFocusOutside = (event) => {
545
- if (rootOpen !== void 0) {
546
- event.preventDefault();
547
- }
548
- onFocusOutside == null ? void 0 : onFocusOutside(event);
549
- };
550
530
  return /* @__PURE__ */ jsxRuntime.jsx(ContentProvider, { containerSpacing, children: /* @__PURE__ */ jsxRuntime.jsx(
551
531
  StyledContent,
552
532
  {
@@ -561,7 +541,6 @@ const Content = React.forwardRef(
561
541
  collisionPadding,
562
542
  sticky,
563
543
  hideWhenDetached,
564
- onFocusOutside: handleFocusOutside,
565
544
  children: /* @__PURE__ */ jsxRuntime.jsx(
566
545
  ScrollableContent,
567
546
  {
@@ -767,45 +746,22 @@ const StyledTrigger = designSystemStitches.styled(RadixDropdownMenu__namespace.T
767
746
  }
768
747
  });
769
748
 
770
- const Trigger = React.forwardRef(
771
- ({ asChild = false, onClick, onPointerDown, onPointerUp, ...restProps }, forwardRef) => {
772
- const ref = React.useRef(null);
773
- const { setOpen, triggerRef } = useDropdownContext();
774
- const isPointerDownRef = React.useRef(false);
775
- const handlePointerDown = (e) => {
776
- isPointerDownRef.current = true;
777
- onPointerDown == null ? void 0 : onPointerDown(e);
778
- };
779
- const handlePointerUp = (e) => {
780
- onPointerUp == null ? void 0 : onPointerUp(e);
781
- };
782
- designSystemUseEventListener.useEventListener("pointerup", (e) => {
783
- if (!isPointerDownRef.current) {
784
- return;
785
- }
786
- isPointerDownRef.current = false;
787
- const isOutsideTrigger = triggerRef.current != null && !triggerRef.current.contains(e.target);
788
- if (isOutsideTrigger) {
789
- setOpen(false);
790
- }
791
- });
792
- return /* @__PURE__ */ jsxRuntime.jsx(
793
- StyledTrigger,
794
- {
795
- ...restProps,
796
- onClick: (e) => {
797
- designSystemUtils.handleVirtualClick(e, ref);
798
- onClick == null ? void 0 : onClick(e);
799
- },
800
- onPointerDown: handlePointerDown,
801
- onPointerUp: handlePointerUp,
802
- ref: designSystemUtils.mergeRefs([ref, triggerRef, forwardRef]),
803
- unstyled: !asChild,
804
- asChild
805
- }
806
- );
807
- }
808
- );
749
+ const Trigger = React.forwardRef(({ asChild = false, onClick, ...restProps }, forwardRef) => {
750
+ const ref = React.useRef(null);
751
+ return /* @__PURE__ */ jsxRuntime.jsx(
752
+ StyledTrigger,
753
+ {
754
+ ...restProps,
755
+ onClick: (e) => {
756
+ designSystemUtils.handleVirtualClick(e, ref);
757
+ onClick == null ? void 0 : onClick(e);
758
+ },
759
+ ref: designSystemUtils.mergeRefs([ref, forwardRef]),
760
+ unstyled: !asChild,
761
+ asChild
762
+ }
763
+ );
764
+ });
809
765
 
810
766
  const StyledIconContainer = designSystemStitches.styled(designSystemPrimitive.Primitive.span, {
811
767
  color: "$icon-neutrals-with-text",
@@ -955,47 +911,36 @@ const Root = ({
955
911
  defaultOpen = false,
956
912
  direction,
957
913
  interactOutside = false,
914
+ open,
958
915
  onOpen,
959
916
  onClose,
960
917
  ...restProps
961
918
  }) => {
962
919
  const { ignoreNextTooltip } = designSystemBaseTooltip.useBaseTooltipContext();
963
- const { open, setOpen, rootOpen } = useDropdownContext();
964
920
  const prevOpen = designSystemUsePrevious.usePrevious(open);
965
921
  React.useEffect(() => {
966
- if (prevOpen !== open) {
967
- if (open === true) {
968
- onOpen == null ? void 0 : onOpen();
969
- } else {
970
- if (prevOpen === true) {
971
- ignoreNextTooltip();
972
- }
973
- onClose == null ? void 0 : onClose();
974
- }
922
+ if (prevOpen === true && open === false) {
923
+ ignoreNextTooltip();
975
924
  }
976
- }, [open, prevOpen, onOpen, onClose, ignoreNextTooltip]);
977
- const isControlled = rootOpen !== void 0;
978
- const resolvedOpen = isControlled ? open : defaultOpen && (prevOpen === void 0 || prevOpen === open) ? (
979
- // only use defaultOpen in the first render then use the context open state
980
- // 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
981
- void 0
982
- ) : (
983
- // otherwise, use the internal open state
984
- open
985
- );
925
+ }, [ignoreNextTooltip, open, prevOpen]);
986
926
  return /* @__PURE__ */ jsxRuntime.jsx(
987
927
  RadixDropdownMenu__namespace.Root,
988
928
  {
989
929
  ...restProps,
990
930
  dir: direction,
991
931
  modal: interactOutside,
992
- open: resolvedOpen,
993
- defaultOpen: isControlled ? void 0 : defaultOpen,
994
- onOpenChange: setOpen
932
+ open,
933
+ defaultOpen,
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
+ }
995
940
  }
996
941
  );
997
942
  };
998
- 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 }) }) });
999
944
  DropdownMenu.CheckboxItem = CheckboxItem;
1000
945
  DropdownMenu.Content = Content;
1001
946
  DropdownMenu.Hotkey = Hotkey;