@@ -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+
6097export 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