@@ -234,28 +234,7 @@ class ToolTipElement extends HTMLElement {
234234 this . #update( false )
235235 this . #allowUpdatePosition = true
236236
237- if ( ! this . control ) return
238-
239- this . setAttribute ( 'role' , 'tooltip' )
240-
241- this . #abortController?. abort ( )
242- this . #abortController = new AbortController ( )
243- const { signal} = this . #abortController
244-
245- this . addEventListener ( 'mouseleave' , this , { signal} )
246- this . addEventListener ( 'toggle' , this , { signal} )
247- this . control . addEventListener ( 'mouseenter' , this , { signal} )
248- this . control . addEventListener ( 'mouseleave' , this , { signal} )
249- this . control . addEventListener ( 'focus' , this , { signal} )
250- this . control . addEventListener ( 'mousedown' , this , { signal} )
251- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
252- // @ts -ignore popoverTargetElement is not in the type definition
253- this . control . popoverTargetElement ?. addEventListener ( 'beforetoggle' , this , {
254- signal,
255- } )
256- this . ownerDocument . addEventListener ( 'focusout' , focusOutListener )
257- this . ownerDocument . addEventListener ( 'focusin' , focusInListener )
258- this . ownerDocument . addEventListener ( 'keydown' , this , { signal, capture : true } )
237+ this . #updateControl( )
259238 }
260239
261240 disconnectedCallback ( ) {
@@ -303,7 +282,7 @@ class ToolTipElement extends HTMLElement {
303282 }
304283 }
305284
306- static observedAttributes = [ 'data-type' , 'data-direction' , 'id' ]
285+ static observedAttributes = [ 'data-type' , 'data-direction' , 'id' , 'for' ]
307286
308287 #update( isOpen : boolean ) {
309288 if ( isOpen ) {
@@ -321,13 +300,40 @@ class ToolTipElement extends HTMLElement {
321300 attributeChangedCallback ( name : string ) {
322301 if ( ! this . isConnected ) return
323302
324- if ( name === 'id' || name === 'data-type' ) {
303+ if ( name === 'for' ) {
304+ this . #updateControl( )
305+ } else if ( name === 'id' || name === 'data-type' ) {
325306 this . #updateControlReference( )
326307 } else if ( name === 'data-direction' ) {
327308 this . #updateDirection( )
328309 }
329310 }
330311
312+ #updateControl( ) {
313+ if ( ! this . control ) return
314+
315+ this . setAttribute ( 'role' , 'tooltip' )
316+
317+ this . #abortController?. abort ( )
318+ this . #abortController = new AbortController ( )
319+ const { signal} = this . #abortController
320+
321+ this . addEventListener ( 'mouseleave' , this , { signal} )
322+ this . addEventListener ( 'toggle' , this , { signal} )
323+ this . control . addEventListener ( 'mouseenter' , this , { signal} )
324+ this . control . addEventListener ( 'mouseleave' , this , { signal} )
325+ this . control . addEventListener ( 'focus' , this , { signal} )
326+ this . control . addEventListener ( 'mousedown' , this , { signal} )
327+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
328+ // @ts -ignore popoverTargetElement is not in the type definition
329+ this . control . popoverTargetElement ?. addEventListener ( 'beforetoggle' , this , {
330+ signal,
331+ } )
332+ this . ownerDocument . addEventListener ( 'focusout' , focusOutListener )
333+ this . ownerDocument . addEventListener ( 'focusin' , focusInListener )
334+ this . ownerDocument . addEventListener ( 'keydown' , this , { signal, capture : true } )
335+ }
336+
331337 #updateControlReference( ) {
332338 if ( ! this . id || ! this . control ) return
333339 if ( this . type === 'label' ) {
0 commit comments