Skip to content

Commit 5388994

Browse files
committed
Popper arrows now flow correctly when auto repositioned
Closes #83
1 parent 192bd5c commit 5388994

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

components/popup/popup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Popper from "popper.js";
1616
<div class="content">{{ config.text }}</div>
1717
</ng-container>
1818
<div #templateSibling></div>
19-
<sui-popup-arrow *ngIf="!config.isBasic" [placement]="_positioningService.placement" [inverted]="config.isInverted"></sui-popup-arrow>
19+
<sui-popup-arrow *ngIf="!config.isBasic" [placement]="_positioningService.actualPlacement" [inverted]="config.isInverted"></sui-popup-arrow>
2020
</div>
2121
`,
2222
styles: [`
@@ -83,7 +83,7 @@ export class SuiPopup implements IPopup {
8383
// Returns the direction (`top`, `left`, `right`, `bottom`) of the current placement.
8484
public get direction() {
8585
if (this._positioningService) {
86-
return this._positioningService.placement.split(" ").shift();
86+
return this._positioningService.actualPlacement.split(" ").shift();
8787
}
8888
}
8989

components/util/positioning.service.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,43 @@ function placementToPopper(placement:PositioningPlacement):PopperPlacement {
5757
return chosenPlacement.join("-") as PopperPlacement;
5858
}
5959

60+
function popperToPlacement(popper:string):PositioningPlacement {
61+
if (!popper || popper == "inherit") {
62+
return "inherit";
63+
}
64+
65+
const [direction, alignment] = popper.split("-");
66+
67+
let chosenPlacement = [direction];
68+
69+
switch (direction) {
70+
case "top":
71+
case "bottom":
72+
switch (alignment) {
73+
case "start":
74+
chosenPlacement.push("left");
75+
break;
76+
case "end":
77+
chosenPlacement.push("right");
78+
break;
79+
}
80+
break;
81+
case "left":
82+
case "right":
83+
switch (alignment) {
84+
case "start":
85+
chosenPlacement.push("top");
86+
break;
87+
case "end":
88+
chosenPlacement.push("bottom");
89+
break;
90+
}
91+
break;
92+
}
93+
94+
return chosenPlacement.join(" ") as PositioningPlacement;
95+
}
96+
6097
export class PositioningService {
6198
public readonly anchor:ElementRef;
6299
public readonly subject:ElementRef;
@@ -65,7 +102,7 @@ export class PositioningService {
65102
private _popperState:Popper.Data;
66103
private _placement:PositioningPlacement;
67104

68-
public get placement():PositioningPlacement {
105+
public get placement() {
69106
return this._placement;
70107
}
71108

@@ -75,6 +112,10 @@ export class PositioningService {
75112
this.update();
76113
}
77114

115+
public get actualPlacement() {
116+
return popperToPlacement(this._popperState.placement);
117+
}
118+
78119
public get state() {
79120
return this._popperState;
80121
}

0 commit comments

Comments
 (0)