Skip to content

Commit 17535fb

Browse files
authored
Merge 769f67f into b4d92bf
2 parents b4d92bf + 769f67f commit 17535fb

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/hooks/useAlign.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,35 @@ export default function useAlign(
164164
if (popupEle && target && open) {
165165
const popupElement = popupEle;
166166

167+
const doc = popupElement.ownerDocument;
168+
const win = getWin(popupElement);
169+
170+
const {
171+
width,
172+
height,
173+
position: popupPosition,
174+
} = win.getComputedStyle(popupElement);
175+
167176
const originLeft = popupElement.style.left;
168177
const originTop = popupElement.style.top;
169178
const originRight = popupElement.style.right;
170179
const originBottom = popupElement.style.bottom;
171180

172-
const doc = popupElement.ownerDocument;
173-
const win = getWin(popupElement);
174-
175181
// Placement
176182
const placementInfo: AlignType = {
177183
...builtinPlacements[placement],
178184
...popupAlign,
179185
};
180186

187+
// placeholder element
188+
const placeholderElement = doc.createElement('div');
189+
popupElement.parentElement?.appendChild(placeholderElement);
190+
placeholderElement.style.left = `${popupElement.offsetLeft}px`;
191+
placeholderElement.style.top = `${popupElement.offsetTop}px`;
192+
placeholderElement.style.position = popupPosition;
193+
placeholderElement.style.height = `${popupElement.offsetHeight}px`;
194+
placeholderElement.style.width = `${popupElement.offsetWidth}px`;
195+
181196
// Reset first
182197
popupElement.style.left = '0';
183198
popupElement.style.top = '0';
@@ -203,7 +218,6 @@ export default function useAlign(
203218
};
204219
}
205220
const popupRect = popupElement.getBoundingClientRect();
206-
const { width, height } = win.getComputedStyle(popupElement);
207221
const {
208222
clientWidth,
209223
clientHeight,
@@ -268,6 +282,8 @@ export default function useAlign(
268282
popupElement.style.right = originRight;
269283
popupElement.style.bottom = originBottom;
270284

285+
popupElement.parentElement?.removeChild(placeholderElement);
286+
271287
// Calculate scale
272288
const scaleX = toNum(
273289
Math.round((popupWidth / parseFloat(width)) * 1000) / 1000,

0 commit comments

Comments
 (0)