Skip to content

Commit f3c0106

Browse files
authored
fix: relative positon incorrect placement on autoUpdate
1 parent e5a14a7 commit f3c0106

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

projects/toppy/src/lib/position/relative-position.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export class RelativePosition extends ToppyPosition {
9999
}
100100

101101
private nextPosition(current: OutsidePlacement): string {
102-
const placements = ['t', 'b', 'l', 'r', 'tl', 'tr', 'bl', 'br', 'lt', 'lb', 'rt', 'rb'];
102+
const placements = ['t', 'b', 'l', 'r', 'tl', 'bl', 'tr', 'br', 'lt', 'rt', 'lb', 'rb'];
103103

104104
const index = placements.indexOf(current);
105105
const even = index % 2 === 0;

projects/toppy/src/tests/positions/relative-position.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('@ RelativePosition', () => {
6161
});
6262

6363
describe('#autoUpdate', () => {
64-
it('should switch if it is true', () => {
64+
it('should switch if it is true - case 1', () => {
6565
const relPos = new RelativePosition({
6666
src: targetElement,
6767
placement: OutsidePlacement.TOP,
@@ -81,6 +81,26 @@ describe('@ RelativePosition', () => {
8181
pos: OutsidePlacement.BOTTOM
8282
});
8383
});
84+
it('should switch if it is true - case 2', () => {
85+
const relPos = new RelativePosition({
86+
src: targetElement,
87+
placement: OutsidePlacement.TOP_LEFT,
88+
height: 500,
89+
autoUpdate: true
90+
});
91+
const srcCoords = targetElement.getBoundingClientRect();
92+
const hostElCoords = {
93+
width: 4, // actual 967
94+
height: 450
95+
};
96+
expect((relPos as any).calculatePos(OutsidePlacement.TOP_LEFT, srcCoords, hostElCoords, true)).toEqual({
97+
props: {
98+
left: 8,
99+
top: srcCoords.top + srcCoords.height
100+
},
101+
pos: OutsidePlacement.BOTTOM_LEFT
102+
});
103+
});
84104
it('should not switch if it is false', () => {
85105
const relPos = new RelativePosition({
86106
src: targetElement,

0 commit comments

Comments
 (0)