Skip to content

Commit

Permalink
fix: popupAlign not merge into builtinPlacement (#339)
Browse files Browse the repository at this point in the history
* fix: align should be auto merged

* test: update test case

* chore: back of

* chore: clean up
  • Loading branch information
zombieJ authored Mar 15, 2023
1 parent 7210d84 commit 85dd06b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/hooks/useAlign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ export default function useAlign(
const win = getWin(popupElement);

// Placement
const placementInfo: AlignType =
builtinPlacements[placement] || popupAlign || {};
const placementInfo: AlignType = {
...builtinPlacements[placement],
...popupAlign,
};

// Reset first
popupElement.style.left = '0';
Expand Down
29 changes: 29 additions & 0 deletions tests/align.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,33 @@ describe('Trigger.Align', () => {
await awaitFakeTimer();
expect(onPopupAlign).not.toHaveBeenCalled();
});

it('align should merge into placement', async () => {
render(
<Trigger
popupVisible
popup={<span className="bamboo" />}
builtinPlacements={{
top: {
targetOffset: [0, 0],
},
}}
popupPlacement="top"
popupAlign={{
targetOffset: [903, 1128],
}}
>
<span />
</Trigger>,
);

await awaitFakeTimer();

expect(
document.querySelector('.rc-trigger-popup-placement-top'),
).toHaveStyle({
left: `753px`,
top: `978px`,
});
});
});

0 comments on commit 85dd06b

Please sign in to comment.