@mirohq/design-system-dropdown-menu 5.3.1 → 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 +8 -6
package/dist/module.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Portal as Portal$1 } from '@radix-ui/react-dropdown-menu';
|
|
|
5
5
|
import { BaseTooltipProvider, useBaseTooltipContext } from '@mirohq/design-system-base-tooltip';
|
|
6
6
|
import { usePrevious } from '@mirohq/design-system-use-previous';
|
|
7
7
|
import { IconProhibit, IconCheckMark, IconMinus, IconChevronRight } from '@mirohq/design-system-icons';
|
|
8
|
-
import { addPropsToChildren, booleanify, mergeRefs
|
|
8
|
+
import { addPropsToChildren, booleanify, mergeRefs } from '@mirohq/design-system-utils';
|
|
9
9
|
import { Primitive } from '@mirohq/design-system-primitive';
|
|
10
10
|
import { styled, theme } from '@mirohq/design-system-stitches';
|
|
11
11
|
import { focus, animations } from '@mirohq/design-system-styles';
|
|
@@ -14,6 +14,8 @@ import { useLayoutEffect } from '@mirohq/design-system-use-layout-effect';
|
|
|
14
14
|
import { useAriaDisabled as useAriaDisabled$1 } from '@mirohq/design-system-use-aria-disabled';
|
|
15
15
|
import { ScrollArea } from '@mirohq/design-system-scroll-area';
|
|
16
16
|
import { styles, Thumb } from '@mirohq/design-system-base-switch';
|
|
17
|
+
import { mergeProps } from '@react-aria/utils';
|
|
18
|
+
import { usePress } from '@mirohq/design-system-use-press';
|
|
17
19
|
import { styles as styles$1, isIconComponent } from '@mirohq/design-system-base-icon';
|
|
18
20
|
|
|
19
21
|
const Context$1 = createContext({
|
|
@@ -459,16 +461,25 @@ const ScrollableContent = ({
|
|
|
459
461
|
const DropdownContext = createContext({});
|
|
460
462
|
const DropdownProvider = ({
|
|
461
463
|
children,
|
|
464
|
+
open: rootOpen,
|
|
462
465
|
...restProps
|
|
463
|
-
}) =>
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
466
|
+
}) => {
|
|
467
|
+
const [open, setOpen] = useState(rootOpen);
|
|
468
|
+
const triggerRef = useRef(null);
|
|
469
|
+
return /* @__PURE__ */ jsx(
|
|
470
|
+
DropdownContext.Provider,
|
|
471
|
+
{
|
|
472
|
+
value: {
|
|
473
|
+
...restProps,
|
|
474
|
+
rootOpen,
|
|
475
|
+
open,
|
|
476
|
+
setOpen,
|
|
477
|
+
triggerRef
|
|
478
|
+
},
|
|
479
|
+
children
|
|
480
|
+
}
|
|
481
|
+
);
|
|
482
|
+
};
|
|
472
483
|
const useDropdownContext = () => useContext(DropdownContext);
|
|
473
484
|
|
|
474
485
|
const Content = React.forwardRef(
|
|
@@ -485,10 +496,11 @@ const Content = React.forwardRef(
|
|
|
485
496
|
containerSpacing = "medium",
|
|
486
497
|
overflow = "visible",
|
|
487
498
|
maxHeight,
|
|
499
|
+
onInteractOutside,
|
|
488
500
|
children,
|
|
489
501
|
...restProps
|
|
490
502
|
}, forwardRef) => {
|
|
491
|
-
const { direction } = useDropdownContext();
|
|
503
|
+
const { direction, triggerRef } = useDropdownContext();
|
|
492
504
|
const preventScrollOnFocus = (ref) => {
|
|
493
505
|
if (ref === null || "_autoScrollPrevented" in ref.focus) {
|
|
494
506
|
return;
|
|
@@ -521,6 +533,12 @@ const Content = React.forwardRef(
|
|
|
521
533
|
collisionPadding,
|
|
522
534
|
sticky,
|
|
523
535
|
hideWhenDetached,
|
|
536
|
+
onInteractOutside: (e) => {
|
|
537
|
+
if (e.target === triggerRef.current) {
|
|
538
|
+
e.preventDefault();
|
|
539
|
+
}
|
|
540
|
+
onInteractOutside == null ? void 0 : onInteractOutside(e);
|
|
541
|
+
},
|
|
524
542
|
children: /* @__PURE__ */ jsx(
|
|
525
543
|
ScrollableContent,
|
|
526
544
|
{
|
|
@@ -726,17 +744,51 @@ const StyledTrigger = styled(RadixDropdownMenu.Trigger, {
|
|
|
726
744
|
}
|
|
727
745
|
});
|
|
728
746
|
|
|
729
|
-
const Trigger = React.forwardRef(({ asChild = false,
|
|
747
|
+
const Trigger = React.forwardRef(({ asChild = false, ...restProps }, forwardRef) => {
|
|
730
748
|
const ref = useRef(null);
|
|
749
|
+
const { setOpen, rootOpen, triggerRef } = useDropdownContext();
|
|
750
|
+
const { pressProps } = usePress({
|
|
751
|
+
onPress: () => {
|
|
752
|
+
if (rootOpen === void 0) {
|
|
753
|
+
setOpen((open) => !booleanify(open));
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
});
|
|
757
|
+
const elementProps = mergeProps(restProps, pressProps);
|
|
758
|
+
const onClickHandler = useCallback(
|
|
759
|
+
(e) => {
|
|
760
|
+
var _a, _b;
|
|
761
|
+
if ((e == null ? void 0 : e.nativeEvent) === void 0) {
|
|
762
|
+
console.error(
|
|
763
|
+
"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))
|
|
764
|
+
);
|
|
765
|
+
(_a = restProps.onClick) == null ? void 0 : _a.call(restProps, e);
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
(_b = elementProps.onClick) == null ? void 0 : _b.call(elementProps, e);
|
|
769
|
+
},
|
|
770
|
+
[restProps, elementProps]
|
|
771
|
+
);
|
|
731
772
|
return /* @__PURE__ */ jsx(
|
|
732
773
|
StyledTrigger,
|
|
733
774
|
{
|
|
734
|
-
...
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
775
|
+
...elementProps,
|
|
776
|
+
onPointerDown: (e) => {
|
|
777
|
+
var _a;
|
|
778
|
+
if (process.env.NODE_ENV === "test") {
|
|
779
|
+
onClickHandler(e);
|
|
780
|
+
}
|
|
781
|
+
(_a = elementProps.onPointerDown) == null ? void 0 : _a.call(elementProps, e);
|
|
782
|
+
},
|
|
783
|
+
onClick: onClickHandler,
|
|
784
|
+
onKeyDown: (e) => {
|
|
785
|
+
var _a;
|
|
786
|
+
if (!/^(Arrow|Tab|Escape)/.test(e.key)) {
|
|
787
|
+
e.preventDefault();
|
|
788
|
+
}
|
|
789
|
+
(_a = elementProps.onKeyDown) == null ? void 0 : _a.call(elementProps, e);
|
|
738
790
|
},
|
|
739
|
-
ref: mergeRefs([ref, forwardRef]),
|
|
791
|
+
ref: mergeRefs([ref, triggerRef, forwardRef]),
|
|
740
792
|
unstyled: !asChild,
|
|
741
793
|
asChild
|
|
742
794
|
}
|
|
@@ -891,36 +943,48 @@ const Root = ({
|
|
|
891
943
|
defaultOpen = false,
|
|
892
944
|
direction,
|
|
893
945
|
interactOutside = false,
|
|
894
|
-
open,
|
|
895
946
|
onOpen,
|
|
896
947
|
onClose,
|
|
897
948
|
...restProps
|
|
898
949
|
}) => {
|
|
899
950
|
const { ignoreNextTooltip } = useBaseTooltipContext();
|
|
951
|
+
const { rootOpen, open, setOpen } = useDropdownContext();
|
|
900
952
|
const prevOpen = usePrevious(open);
|
|
901
953
|
useEffect(() => {
|
|
902
|
-
if (prevOpen
|
|
903
|
-
|
|
954
|
+
if (prevOpen !== open) {
|
|
955
|
+
if (open === true) {
|
|
956
|
+
onOpen == null ? void 0 : onOpen();
|
|
957
|
+
} else {
|
|
958
|
+
if (prevOpen === true) {
|
|
959
|
+
ignoreNextTooltip();
|
|
960
|
+
}
|
|
961
|
+
onClose == null ? void 0 : onClose();
|
|
962
|
+
}
|
|
904
963
|
}
|
|
905
|
-
}, [
|
|
964
|
+
}, [open, prevOpen, onOpen, onClose, ignoreNextTooltip]);
|
|
906
965
|
return /* @__PURE__ */ jsx(
|
|
907
966
|
RadixDropdownMenu.Root,
|
|
908
967
|
{
|
|
909
968
|
...restProps,
|
|
910
969
|
dir: direction,
|
|
911
970
|
modal: interactOutside,
|
|
912
|
-
open
|
|
971
|
+
open: (
|
|
972
|
+
// use the root open state if it is defined
|
|
973
|
+
rootOpen != null ? rootOpen : defaultOpen && (prevOpen === void 0 || prevOpen === open) ? (
|
|
974
|
+
// only use defaultOpen in the first render then use the context open state
|
|
975
|
+
// 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
|
|
976
|
+
void 0
|
|
977
|
+
) : (
|
|
978
|
+
// otherwise, use the user open state
|
|
979
|
+
open
|
|
980
|
+
)
|
|
981
|
+
),
|
|
913
982
|
defaultOpen,
|
|
914
|
-
onOpenChange:
|
|
915
|
-
if (!newOpen && open === void 0) {
|
|
916
|
-
ignoreNextTooltip();
|
|
917
|
-
}
|
|
918
|
-
newOpen ? onOpen == null ? void 0 : onOpen() : onClose == null ? void 0 : onClose();
|
|
919
|
-
}
|
|
983
|
+
onOpenChange: setOpen
|
|
920
984
|
}
|
|
921
985
|
);
|
|
922
986
|
};
|
|
923
|
-
const DropdownMenu = ({ direction = "ltr", ...restProps }) => /* @__PURE__ */ jsx(DropdownProvider, { direction, children: /* @__PURE__ */ jsx(BaseTooltipProvider, { children: /* @__PURE__ */ jsx(Root, { direction, ...restProps }) }) });
|
|
987
|
+
const DropdownMenu = ({ direction = "ltr", open, ...restProps }) => /* @__PURE__ */ jsx(DropdownProvider, { direction, open, children: /* @__PURE__ */ jsx(BaseTooltipProvider, { children: /* @__PURE__ */ jsx(Root, { direction, ...restProps }) }) });
|
|
924
988
|
DropdownMenu.CheckboxItem = CheckboxItem;
|
|
925
989
|
DropdownMenu.Content = Content;
|
|
926
990
|
DropdownMenu.Hotkey = Hotkey;
|