Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/hooks/useAlign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ export default function useAlign(
const originRight = popupElement.style.right;
const originBottom = popupElement.style.bottom;
const originOverflow = popupElement.style.overflow;
const originOverflowX = popupElement.style.overflowX;
const originOverflowY = popupElement.style.overflowY;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This extra empty line is redundant and deviates from the existing code style in this file. It's recommended to remove it to keep the code clean and maintain consistent spacing.


// Placement
const placementInfo: AlignType = {
Expand Down Expand Up @@ -295,6 +298,8 @@ export default function useAlign(
popupElement.style.right = originRight;
popupElement.style.bottom = originBottom;
popupElement.style.overflow = originOverflow;
popupElement.style.overflowX = originOverflowX;
popupElement.style.overflowY = originOverflowY;

popupElement.parentElement?.removeChild(placeholderElement);

Expand Down
34 changes: 34 additions & 0 deletions tests/align.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,40 @@ describe('Trigger.Align', () => {
});
});

it('should restore overflowX and overflowY after align', async () => {
const triggerRef = React.createRef<TriggerRef>();

render(
<Trigger
popupVisible
popup={<span className="bamboo" />}
popupStyle={{
overflowX: 'auto',
overflowY: 'scroll',
}}
ref={triggerRef}
>
<div />
</Trigger>,
);

await awaitFakeTimer();

const popupElement = document.querySelector(
'.rc-trigger-popup',
) as HTMLElement;
expect(popupElement.style.overflowX).toBe('auto');
expect(popupElement.style.overflowY).toBe('scroll');

act(() => {
triggerRef.current!.forceAlign();
});
await awaitFakeTimer();

expect(popupElement.style.overflowX).toBe('auto');
expect(popupElement.style.overflowY).toBe('scroll');
});

it('targetOffset support ptg', async () => {
render(
<Trigger
Expand Down