Skip to content

Commit 85dd06b

Browse files
authored
fix: popupAlign not merge into builtinPlacement (#339)
* fix: align should be auto merged * test: update test case * chore: back of * chore: clean up
1 parent 7210d84 commit 85dd06b

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/hooks/useAlign.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ export default function useAlign(
128128
const win = getWin(popupElement);
129129

130130
// Placement
131-
const placementInfo: AlignType =
132-
builtinPlacements[placement] || popupAlign || {};
131+
const placementInfo: AlignType = {
132+
...builtinPlacements[placement],
133+
...popupAlign,
134+
};
133135

134136
// Reset first
135137
popupElement.style.left = '0';

tests/align.test.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,33 @@ describe('Trigger.Align', () => {
176176
await awaitFakeTimer();
177177
expect(onPopupAlign).not.toHaveBeenCalled();
178178
});
179+
180+
it('align should merge into placement', async () => {
181+
render(
182+
<Trigger
183+
popupVisible
184+
popup={<span className="bamboo" />}
185+
builtinPlacements={{
186+
top: {
187+
targetOffset: [0, 0],
188+
},
189+
}}
190+
popupPlacement="top"
191+
popupAlign={{
192+
targetOffset: [903, 1128],
193+
}}
194+
>
195+
<span />
196+
</Trigger>,
197+
);
198+
199+
await awaitFakeTimer();
200+
201+
expect(
202+
document.querySelector('.rc-trigger-popup-placement-top'),
203+
).toHaveStyle({
204+
left: `753px`,
205+
top: `978px`,
206+
});
207+
});
179208
});

0 commit comments

Comments
 (0)