@@ -319,22 +319,43 @@ function applyFromToolbar(event: Event) {
319
319
applyStyle ( target , style )
320
320
}
321
321
322
+ function setFocusManagement ( toolbar : MarkdownToolbarElement ) {
323
+ toolbar . addEventListener ( 'keydown' , focusKeydown )
324
+ toolbar . setAttribute ( 'tabindex' , '0' )
325
+ toolbar . addEventListener ( 'focus' , onToolbarFocus , { once : true } )
326
+ }
327
+
328
+ function unsetFocusManagement ( toolbar : MarkdownToolbarElement ) {
329
+ toolbar . removeEventListener ( 'keydown' , focusKeydown )
330
+ toolbar . removeAttribute ( 'tabindex' )
331
+ toolbar . removeEventListener ( 'focus' , onToolbarFocus )
332
+ }
333
+
322
334
class MarkdownToolbarElement extends HTMLElement {
335
+ static observedAttributes = [ 'data-no-focus' ]
336
+
323
337
connectedCallback ( ) : void {
324
338
if ( ! this . hasAttribute ( 'role' ) ) {
325
339
this . setAttribute ( 'role' , 'toolbar' )
326
340
}
327
341
if ( ! this . hasAttribute ( 'data-no-focus' ) ) {
328
- this . addEventListener ( 'keydown' , focusKeydown )
329
- this . setAttribute ( 'tabindex' , '0' )
330
- this . addEventListener ( 'focus' , onToolbarFocus , { once : true } )
342
+ setFocusManagement ( this )
331
343
}
332
344
this . addEventListener ( 'keydown' , keydown ( applyFromToolbar ) )
333
345
this . addEventListener ( 'click' , applyFromToolbar )
334
346
}
335
347
348
+ attributeChangedCallback ( name : string , oldValue : string , newValue : string ) : void {
349
+ if ( name !== 'data-no-focus' ) return
350
+ if ( newValue === null ) {
351
+ setFocusManagement ( this )
352
+ } else {
353
+ unsetFocusManagement ( this )
354
+ }
355
+ }
356
+
336
357
disconnectedCallback ( ) : void {
337
- this . removeEventListener ( 'keydown' , focusKeydown )
358
+ unsetFocusManagement ( this )
338
359
}
339
360
340
361
get field ( ) : HTMLTextAreaElement | null {
0 commit comments