@@ -58,9 +58,16 @@ class BlaBlaBlocksInfotip extends HTMLElement {
5858 strategy : 'fixed' ,
5959 middleware : [
6060 floatingUIDOM . offset ( parseInt ( offset ) ) ,
61- floatingUIDOM . flip ( ) ,
61+ floatingUIDOM . flip ( {
62+ fallbackPlacements : [
63+ 'top' ,
64+ 'right' ,
65+ 'bottom' ,
66+ 'left' ,
67+ ] ,
68+ } ) ,
6269 floatingUIDOM . shift ( { padding : 5 } ) ,
63- floatingUIDOM . arrow ( { element : arrow } ) ,
70+ floatingUIDOM . arrow ( { element : arrow , padding : 5 } ) ,
6471 ] ,
6572 } )
6673 . then ( ( { x, y, placement, middlewareData } ) => {
@@ -69,22 +76,34 @@ class BlaBlaBlocksInfotip extends HTMLElement {
6976 top : `${ y } px` ,
7077 } ) ;
7178
72- const { x : arrowX , y : arrowY } = middlewareData . arrow ;
73-
74- const staticSide = {
75- top : 'bottom' ,
76- right : 'left' ,
77- bottom : 'top' ,
78- left : 'right' ,
79- } [ placement . split ( '-' ) [ 0 ] ] ;
80-
81- Object . assign ( arrow . style , {
82- left : arrowX !== null ? `${ arrowX } px` : '' ,
83- top : arrowY !== null ? `${ arrowY } px` : '' ,
84- right : '' ,
85- bottom : '' ,
86- [ staticSide ] : '-4px' ,
87- } ) ;
79+ // Extract the base placement (first part before any hyphen)
80+ const basePlacement = placement . split ( '-' ) [ 0 ] ;
81+
82+ // Arrow positioning
83+ if ( middlewareData . arrow ) {
84+ const { x : arrowX , y : arrowY } = middlewareData . arrow ;
85+
86+ // Reset all positions first
87+ arrow . style . left = '' ;
88+ arrow . style . top = '' ;
89+ arrow . style . right = '' ;
90+ arrow . style . bottom = '' ;
91+
92+ // Set the arrow position based on the base placement
93+ if ( basePlacement === 'top' ) {
94+ arrow . style . bottom = '-4px' ;
95+ arrow . style . left = arrowX ? `${ arrowX } px` : '' ;
96+ } else if ( basePlacement === 'bottom' ) {
97+ arrow . style . top = '-4px' ;
98+ arrow . style . left = arrowX ? `${ arrowX } px` : '' ;
99+ } else if ( basePlacement === 'left' ) {
100+ arrow . style . right = '-4px' ;
101+ arrow . style . top = arrowY ? `${ arrowY } px` : '' ;
102+ } else if ( basePlacement === 'right' ) {
103+ arrow . style . left = '-4px' ;
104+ arrow . style . top = arrowY ? `${ arrowY } px` : '' ;
105+ }
106+ }
88107 } ) ;
89108 }
90109
0 commit comments