File tree 2 files changed +10
-0
lines changed
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 {
303
303
304
304
function onToolbarFocus ( { target} : FocusEvent ) {
305
305
if ( ! ( target instanceof Element ) ) return
306
+ if ( target . hasAttribute ( 'data-no-focus' ) ) return
306
307
target . removeAttribute ( 'tabindex' )
307
308
let tabindex = '0'
308
309
for ( const button of getButtons ( target ) ) {
@@ -319,6 +320,7 @@ function focusKeydown(event: KeyboardEvent) {
319
320
if ( key !== 'ArrowRight' && key !== 'ArrowLeft' && key !== 'Home' && key !== 'End' ) return
320
321
const toolbar = event . currentTarget
321
322
if ( ! ( toolbar instanceof HTMLElement ) ) return
323
+ if ( toolbar . hasAttribute ( 'data-no-focus' ) ) return
322
324
const buttons = getButtons ( toolbar )
323
325
const index = buttons . indexOf ( event . target as HTMLElement )
324
326
const length = buttons . length
Original file line number Diff line number Diff line change @@ -131,6 +131,14 @@ describe('markdown-toolbar-element', function () {
131
131
assert . deepEqual ( getElementsWithTabindex ( 0 ) , [ document . activeElement ] )
132
132
} )
133
133
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
+
134
142
it ( 'cycles focus round to last element from first when ArrowLeft is pressed' , function ( ) {
135
143
focusFirstButton ( )
136
144
pushKeyOnFocussedButton ( 'ArrowLeft' )
You can’t perform that action at this time.
0 commit comments