File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -303,6 +303,7 @@ class MarkdownToolbarElement extends HTMLElement {
303303
304304function onToolbarFocus ( { target} : FocusEvent ) {
305305 if ( ! ( target instanceof Element ) ) return
306+ if ( target . hasAttribute ( 'data-no-focus' ) ) return
306307 target . removeAttribute ( 'tabindex' )
307308 let tabindex = '0'
308309 for ( const button of getButtons ( target ) ) {
@@ -319,6 +320,7 @@ function focusKeydown(event: KeyboardEvent) {
319320 if ( key !== 'ArrowRight' && key !== 'ArrowLeft' && key !== 'Home' && key !== 'End' ) return
320321 const toolbar = event . currentTarget
321322 if ( ! ( toolbar instanceof HTMLElement ) ) return
323+ if ( toolbar . hasAttribute ( 'data-no-focus' ) ) return
322324 const buttons = getButtons ( toolbar )
323325 const index = buttons . indexOf ( event . target as HTMLElement )
324326 const length = buttons . length
Original file line number Diff line number Diff line change @@ -131,6 +131,14 @@ describe('markdown-toolbar-element', function () {
131131 assert . deepEqual ( getElementsWithTabindex ( 0 ) , [ document . activeElement ] )
132132 } )
133133
134+ it ( 'does not move focus if `data-no-focus` is present' , function ( ) {
135+ document . querySelector ( 'markdown-toolbar' ) . setAttribute ( 'data-no-focus' , '' )
136+ focusFirstButton ( )
137+ pushKeyOnFocussedButton ( 'ArrowRight' )
138+ assert . deepEqual ( getElementsWithTabindex ( 0 ) , [ document . querySelector ( 'md-bold' ) ] )
139+ assert . deepEqual ( getElementsWithTabindex ( 0 ) , [ document . activeElement ] )
140+ } )
141+
134142 it ( 'cycles focus round to last element from first when ArrowLeft is pressed' , function ( ) {
135143 focusFirstButton ( )
136144 pushKeyOnFocussedButton ( 'ArrowLeft' )
You can’t perform that action at this time.
0 commit comments