@@ -234,28 +234,7 @@ class ToolTipElement extends HTMLElement {
234
234
this . #update( false )
235
235
this . #allowUpdatePosition = true
236
236
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( )
259
238
}
260
239
261
240
disconnectedCallback ( ) {
@@ -303,7 +282,7 @@ class ToolTipElement extends HTMLElement {
303
282
}
304
283
}
305
284
306
- static observedAttributes = [ 'data-type' , 'data-direction' , 'id' ]
285
+ static observedAttributes = [ 'data-type' , 'data-direction' , 'id' , 'for' ]
307
286
308
287
#update( isOpen : boolean ) {
309
288
if ( isOpen ) {
@@ -321,13 +300,40 @@ class ToolTipElement extends HTMLElement {
321
300
attributeChangedCallback ( name : string ) {
322
301
if ( ! this . isConnected ) return
323
302
324
- if ( name === 'id' || name === 'data-type' ) {
303
+ if ( name === 'for' ) {
304
+ this . #updateControl( )
305
+ } else if ( name === 'id' || name === 'data-type' ) {
325
306
this . #updateControlReference( )
326
307
} else if ( name === 'data-direction' ) {
327
308
this . #updateDirection( )
328
309
}
329
310
}
330
311
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
+
331
337
#updateControlReference( ) {
332
338
if ( ! this . id || ! this . control ) return
333
339
if ( this . type === 'label' ) {
0 commit comments