@uniai-fe/uds-templates 0.5.8 → 0.5.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/package.json
CHANGED
|
@@ -32,6 +32,7 @@ export function ModalRoot({
|
|
|
32
32
|
}: ModalRootProps) {
|
|
33
33
|
const { updateModal, closeModal } = useModal();
|
|
34
34
|
const surfaceRef = useRef<HTMLDivElement | null>(null);
|
|
35
|
+
const isPointerDownOutsideRef = useRef(false);
|
|
35
36
|
|
|
36
37
|
useEffect(() => {
|
|
37
38
|
if (modalProps.show === "init") {
|
|
@@ -55,6 +56,40 @@ export function ModalRoot({
|
|
|
55
56
|
closeModal({ stackKey });
|
|
56
57
|
}, [closeModal, modalProps.closeOnOutsideClick, stackKey]);
|
|
57
58
|
|
|
59
|
+
const isOutsideSurface = useCallback((eventTarget: EventTarget | null) => {
|
|
60
|
+
const surface = surfaceRef.current;
|
|
61
|
+
return (
|
|
62
|
+
!(eventTarget instanceof Node) ||
|
|
63
|
+
!surface ||
|
|
64
|
+
!surface.contains(eventTarget)
|
|
65
|
+
);
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
const handlePointerDown = useCallback(
|
|
69
|
+
(event: React.PointerEvent<HTMLDivElement>) => {
|
|
70
|
+
isPointerDownOutsideRef.current = isOutsideSurface(event.target);
|
|
71
|
+
},
|
|
72
|
+
[isOutsideSurface],
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const handlePointerUp = useCallback(
|
|
76
|
+
(event: React.PointerEvent<HTMLDivElement>) => {
|
|
77
|
+
const shouldClose =
|
|
78
|
+
isPointerDownOutsideRef.current && isOutsideSurface(event.target);
|
|
79
|
+
|
|
80
|
+
isPointerDownOutsideRef.current = false;
|
|
81
|
+
|
|
82
|
+
if (shouldClose) {
|
|
83
|
+
handleClose();
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
[handleClose, isOutsideSurface],
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const handlePointerCancel = useCallback(() => {
|
|
90
|
+
isPointerDownOutsideRef.current = false;
|
|
91
|
+
}, []);
|
|
92
|
+
|
|
58
93
|
const stopPropagation = useCallback(
|
|
59
94
|
(event: React.MouseEvent<HTMLDivElement>) => {
|
|
60
95
|
event.stopPropagation();
|
|
@@ -94,7 +129,9 @@ export function ModalRoot({
|
|
|
94
129
|
className={clsx("uds-modal-root", className)}
|
|
95
130
|
data-state={dataState}
|
|
96
131
|
style={layerStyle}
|
|
97
|
-
|
|
132
|
+
onPointerDown={handlePointerDown}
|
|
133
|
+
onPointerUp={handlePointerUp}
|
|
134
|
+
onPointerCancel={handlePointerCancel}
|
|
98
135
|
role="presentation"
|
|
99
136
|
>
|
|
100
137
|
<div className="uds-modal-dimmer" />
|