Skip to content
This repository was archived by the owner on Nov 4, 2025. It is now read-only.

Commit 0b1e3f2

Browse files
committed
Recheck points after dom-align adjustment
1 parent 8418bba commit 0b1e3f2

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/Align.jsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,37 @@ class Align extends Component {
145145

146146
restoreFocus(activeElement, source);
147147

148+
// get correct points
149+
// in dom-align, points will be reset after failed match
150+
// https://github.com/ant-design/ant-design/issues/14582
151+
if (result.overflow.adjustX || result.overflow.adjustY) {
152+
const sourceOffset = source.getBoundingClientRect();
153+
const targetOffset = element.getBoundingClientRect();
154+
const sourceCenter = {
155+
left: sourceOffset.left + sourceOffset.width / 2,
156+
top: sourceOffset.top + sourceOffset.height / 2,
157+
};
158+
const targetCenter = {
159+
left: targetOffset.left + targetOffset.width / 2,
160+
top: targetOffset.top + targetOffset.height / 2,
161+
}
162+
const ratio = (sourceCenter.left - targetCenter.left) / (sourceCenter.top - targetCenter.top);
163+
if (ratio >= -1 || ratio <= 1) {
164+
if (sourceCenter.top < targetCenter.top) {
165+
result.points = ["bc", "tc"];
166+
} else {
167+
result.points = ["tc", "bc"];
168+
}
169+
} else {
170+
/* eslint-disable-next-line */
171+
if (sourceCenter.left < targetCenter.left) {
172+
result.points = ["rc", "lc"];
173+
} else {
174+
result.points = ["lc", "rc"];
175+
}
176+
}
177+
}
178+
148179
if (onAlign) {
149180
onAlign(source, result);
150181
}

0 commit comments

Comments
 (0)