@@ -69,7 +69,7 @@ class Tooltip {
6969 this . #target. setAttribute ( 'style' , 'position: relative' )
7070
7171 this . #createTooltip( )
72- this . #tooltip. classList . add ( this . #containerClassName || ' __tooltip' , ` __tooltip-${ this . #position} `)
72+ this . #tooltip. setAttribute ( 'class' , this . #containerClassName || ` __tooltip __tooltip-${ this . #position} `)
7373
7474 disabled ? this . #disableTarget( ) : this . #enableTarget( )
7575
@@ -94,6 +94,7 @@ class Tooltip {
9494 const hasContentChanged = contentSelector !== this . #contentSelector || content !== this . #content
9595 const hasContainerClassNameChanged = containerClassName !== this . #containerClassName
9696 const hasPositionChanged = position !== this . #position
97+ const hasOffsetChanged = position !== this . #offset
9798 const hasToDisableTarget = disabled && this . #boundEnterHandler
9899 const hasToEnableTarget = ! disabled && ! this . #boundEnterHandler
99100
@@ -110,12 +111,12 @@ class Tooltip {
110111 this . #leaveDelay = leaveDelay || 0
111112 this . #offset = Math . max ( offset || 10 , 5 )
112113
113- if ( hasContentChanged ) {
114+ if ( hasContentChanged || hasPositionChanged || hasOffsetChanged ) {
114115 this . #removeTooltipFromTarget( )
115116 this . #createTooltip( )
116117 }
117118
118- if ( hasContainerClassNameChanged || hasContentChanged || hasPositionChanged ) {
119+ if ( hasContainerClassNameChanged || hasContentChanged || hasPositionChanged || hasOffsetChanged ) {
119120 this . #tooltip. setAttribute ( 'class' , this . #containerClassName || `__tooltip __tooltip-${ this . #position} ` )
120121 }
121122
@@ -167,6 +168,38 @@ class Tooltip {
167168 const child = document . createTextNode ( this . #content)
168169 this . #tooltip. appendChild ( child )
169170 }
171+
172+ this . #createAndAddTooltipArea( )
173+ }
174+
175+ #createAndAddTooltipArea( ) {
176+ const area = document . createElement ( 'div' )
177+ area . setAttribute ( 'aria-hidden' , 'true' )
178+ area . setAttribute ( 'class' , '__tooltip-area' )
179+ switch ( this . #position) {
180+ case 'left' : {
181+ area . setAttribute ( 'style' , `width: calc(100% + ${ this . #offset} px)` )
182+ break
183+ }
184+ case 'right' : {
185+ area . setAttribute (
186+ 'style' ,
187+ `width: calc(100% + ${ this . #offset} px); margin-left: calc(-0.5rem - ${ this . #offset} px)`
188+ )
189+ break
190+ }
191+ case 'bottom' : {
192+ area . setAttribute (
193+ 'style' ,
194+ `height: calc(100% + ${ this . #offset} px); margin-top: calc(-0.5rem - ${ this . #offset} px)`
195+ )
196+ break
197+ }
198+ default : {
199+ area . setAttribute ( 'style' , `height: calc(100% + ${ this . #offset} px)` )
200+ }
201+ }
202+ this . #tooltip. appendChild ( area )
170203 }
171204
172205 #positionTooltip( ) {
0 commit comments