@mirohq/design-system-dropdown-menu 5.3.0 → 5.3.2-dropdown-on-pointerup.3
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 +92 -28
- package/dist/main.js.map +1 -1
- package/dist/module.js +93 -29
- package/dist/module.js.map +1 -1
- package/package.json +9 -7
package/dist/main.js
CHANGED
|
@@ -15,6 +15,8 @@ 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');
|
|
18
20
|
var designSystemBaseIcon = require('@mirohq/design-system-base-icon');
|
|
19
21
|
|
|
20
22
|
function _interopNamespaceDefault(e) {
|
|
@@ -479,16 +481,25 @@ const ScrollableContent = ({
|
|
|
479
481
|
const DropdownContext = React.createContext({});
|
|
480
482
|
const DropdownProvider = ({
|
|
481
483
|
children,
|
|
484
|
+
open: rootOpen,
|
|
482
485
|
...restProps
|
|
483
|
-
}) =>
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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
|
+
};
|
|
492
503
|
const useDropdownContext = () => React.useContext(DropdownContext);
|
|
493
504
|
|
|
494
505
|
const Content = React.forwardRef(
|
|
@@ -505,10 +516,11 @@ const Content = React.forwardRef(
|
|
|
505
516
|
containerSpacing = "medium",
|
|
506
517
|
overflow = "visible",
|
|
507
518
|
maxHeight,
|
|
519
|
+
onInteractOutside,
|
|
508
520
|
children,
|
|
509
521
|
...restProps
|
|
510
522
|
}, forwardRef) => {
|
|
511
|
-
const { direction } = useDropdownContext();
|
|
523
|
+
const { direction, triggerRef } = useDropdownContext();
|
|
512
524
|
const preventScrollOnFocus = (ref) => {
|
|
513
525
|
if (ref === null || "_autoScrollPrevented" in ref.focus) {
|
|
514
526
|
return;
|
|
@@ -541,6 +553,12 @@ const Content = React.forwardRef(
|
|
|
541
553
|
collisionPadding,
|
|
542
554
|
sticky,
|
|
543
555
|
hideWhenDetached,
|
|
556
|
+
onInteractOutside: (e) => {
|
|
557
|
+
if (e.target === triggerRef.current) {
|
|
558
|
+
e.preventDefault();
|
|
559
|
+
}
|
|
560
|
+
onInteractOutside == null ? void 0 : onInteractOutside(e);
|
|
561
|
+
},
|
|
544
562
|
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
545
563
|
ScrollableContent,
|
|
546
564
|
{
|
|
@@ -746,17 +764,51 @@ const StyledTrigger = designSystemStitches.styled(RadixDropdownMenu__namespace.T
|
|
|
746
764
|
}
|
|
747
765
|
});
|
|
748
766
|
|
|
749
|
-
const Trigger = React.forwardRef(({ asChild = false,
|
|
767
|
+
const Trigger = React.forwardRef(({ asChild = false, ...restProps }, forwardRef) => {
|
|
750
768
|
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
|
+
);
|
|
751
792
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
752
793
|
StyledTrigger,
|
|
753
794
|
{
|
|
754
|
-
...
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
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);
|
|
758
810
|
},
|
|
759
|
-
ref: designSystemUtils.mergeRefs([ref, forwardRef]),
|
|
811
|
+
ref: designSystemUtils.mergeRefs([ref, triggerRef, forwardRef]),
|
|
760
812
|
unstyled: !asChild,
|
|
761
813
|
asChild
|
|
762
814
|
}
|
|
@@ -911,36 +963,48 @@ const Root = ({
|
|
|
911
963
|
defaultOpen = false,
|
|
912
964
|
direction,
|
|
913
965
|
interactOutside = false,
|
|
914
|
-
open,
|
|
915
966
|
onOpen,
|
|
916
967
|
onClose,
|
|
917
968
|
...restProps
|
|
918
969
|
}) => {
|
|
919
970
|
const { ignoreNextTooltip } = designSystemBaseTooltip.useBaseTooltipContext();
|
|
971
|
+
const { rootOpen, open, setOpen } = useDropdownContext();
|
|
920
972
|
const prevOpen = designSystemUsePrevious.usePrevious(open);
|
|
921
973
|
React.useEffect(() => {
|
|
922
|
-
if (prevOpen
|
|
923
|
-
|
|
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
|
+
}
|
|
924
983
|
}
|
|
925
|
-
}, [
|
|
984
|
+
}, [open, prevOpen, onOpen, onClose, ignoreNextTooltip]);
|
|
926
985
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
927
986
|
RadixDropdownMenu__namespace.Root,
|
|
928
987
|
{
|
|
929
988
|
...restProps,
|
|
930
989
|
dir: direction,
|
|
931
990
|
modal: interactOutside,
|
|
932
|
-
open
|
|
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
|
+
),
|
|
933
1002
|
defaultOpen,
|
|
934
|
-
onOpenChange:
|
|
935
|
-
if (!newOpen && open === void 0) {
|
|
936
|
-
ignoreNextTooltip();
|
|
937
|
-
}
|
|
938
|
-
newOpen ? onOpen == null ? void 0 : onOpen() : onClose == null ? void 0 : onClose();
|
|
939
|
-
}
|
|
1003
|
+
onOpenChange: setOpen
|
|
940
1004
|
}
|
|
941
1005
|
);
|
|
942
1006
|
};
|
|
943
|
-
const DropdownMenu = ({ direction = "ltr", ...restProps }) => /* @__PURE__ */ jsxRuntime.jsx(DropdownProvider, { direction, children: /* @__PURE__ */ jsxRuntime.jsx(designSystemBaseTooltip.BaseTooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(Root, { direction, ...restProps }) }) });
|
|
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 }) }) });
|
|
944
1008
|
DropdownMenu.CheckboxItem = CheckboxItem;
|
|
945
1009
|
DropdownMenu.Content = Content;
|
|
946
1010
|
DropdownMenu.Hotkey = Hotkey;
|