Skip to content

Commit 612011a

Browse files
committed
fix(ui): calculate click position
1 parent 454c2ba commit 612011a

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

packages/ui/src/components/modal/Modal.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export const DModal: {
136136
} else if (modalContentRef.current) {
137137
const left = `${(ROOT_DATA.pageSize.width - modalContentRef.current.offsetWidth) / 2}px`;
138138
const top = dTop === 'center' ? `${(ROOT_DATA.pageSize.height - modalContentRef.current.offsetHeight) / 2}px` : topStyle;
139-
dataRef.current.transformOrigin = `calc(${ROOT_DATA.clickEvent.e.clientX}px - ${left}) calc(${ROOT_DATA.clickEvent.e.clientY}px - ${top})`;
139+
dataRef.current.transformOrigin = `calc(${ROOT_DATA.clickEvent.x}px - ${left}) calc(${ROOT_DATA.clickEvent.y}px - ${top})`;
140140
}
141141
}}
142142
afterEnter={() => {

packages/ui/src/components/root/Root.tsx

+10-5
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const ROOT = new DConfigContextManager({
2929
export const ROOT_DATA: {
3030
clickEvent?: {
3131
time: number;
32-
e: MouseEvent;
32+
x: number;
33+
y: number;
3334
};
3435
pageSize: { width: number; height: number };
3536
} = {
@@ -96,10 +97,14 @@ export function DRoot(props: DRootProps): JSX.Element | null {
9697
(e) => {
9798
// Check if click by keydown.
9899
if (!(e.clientX === 0 && e.clientY === 0)) {
99-
ROOT_DATA.clickEvent = {
100-
time: performance.now(),
101-
e,
102-
};
100+
const rect = e.target instanceof Element ? e.target.getBoundingClientRect() : null;
101+
if (rect) {
102+
ROOT_DATA.clickEvent = {
103+
time: performance.now(),
104+
x: e.offsetX + rect.x,
105+
y: e.offsetX + rect.y,
106+
};
107+
}
103108
}
104109
},
105110
{ capture: true }

0 commit comments

Comments
 (0)