Skip to content

Commit e22c60b

Browse files
committed
fix(align): restore overflowX and overflowY after force align
1 parent 59b659d commit e22c60b

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/hooks/useAlign.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ export default function useAlign(
184184
const originRight = popupElement.style.right;
185185
const originBottom = popupElement.style.bottom;
186186
const originOverflow = popupElement.style.overflow;
187+
const originOverflowX = popupElement.style.overflowX;
188+
const originOverflowY = popupElement.style.overflowY;
189+
187190

188191
// Placement
189192
const placementInfo: AlignType = {
@@ -295,6 +298,8 @@ export default function useAlign(
295298
popupElement.style.right = originRight;
296299
popupElement.style.bottom = originBottom;
297300
popupElement.style.overflow = originOverflow;
301+
popupElement.style.overflowX = originOverflowX;
302+
popupElement.style.overflowY = originOverflowY;
298303

299304
popupElement.parentElement?.removeChild(placeholderElement);
300305

tests/align.test.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,40 @@ describe('Trigger.Align', () => {
226226
});
227227
});
228228

229+
it('should restore overflowX and overflowY after align', async () => {
230+
const triggerRef = React.createRef<TriggerRef>();
231+
232+
render(
233+
<Trigger
234+
popupVisible
235+
popup={<span className="bamboo" />}
236+
popupStyle={{
237+
overflowX: 'auto',
238+
overflowY: 'scroll',
239+
}}
240+
ref={triggerRef}
241+
>
242+
<div />
243+
</Trigger>,
244+
);
245+
246+
await awaitFakeTimer();
247+
248+
const popupElement = document.querySelector(
249+
'.rc-trigger-popup',
250+
) as HTMLElement;
251+
expect(popupElement.style.overflowX).toBe('auto');
252+
expect(popupElement.style.overflowY).toBe('scroll');
253+
254+
act(() => {
255+
triggerRef.current!.forceAlign();
256+
});
257+
await awaitFakeTimer();
258+
259+
expect(popupElement.style.overflowX).toBe('auto');
260+
expect(popupElement.style.overflowY).toBe('scroll');
261+
});
262+
229263
it('targetOffset support ptg', async () => {
230264
render(
231265
<Trigger

0 commit comments

Comments
 (0)