-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement roving tabindex on grouped blocks toolbars (#23216)
* Implement roving tabindex on grouped blocks toolbars * Fix styles * Use alt+F10 to focus toolbar on e2e tests * Rename e2e test helpers * Fix styles
- Loading branch information
Showing
2 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/e2e-tests/specs/editor/various/toolbar-roving-tabindex.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { | ||
createNewPost, | ||
pressKeyWithModifier, | ||
insertBlock, | ||
} from '@wordpress/e2e-test-utils'; | ||
|
||
async function focusBlockToolbar() { | ||
await pressKeyWithModifier( 'alt', 'F10' ); | ||
} | ||
|
||
async function expectLabelToHaveFocus( label ) { | ||
await expect( | ||
await page.evaluate( () => | ||
document.activeElement.getAttribute( 'aria-label' ) | ||
) | ||
).toBe( label ); | ||
} | ||
|
||
async function testBlockToolbarKeyboardNavigation( currentBlockLabel ) { | ||
await focusBlockToolbar(); | ||
await expectLabelToHaveFocus( 'Change block type or style' ); | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await expectLabelToHaveFocus( 'Move up' ); | ||
await page.keyboard.press( 'Tab' ); | ||
await expectLabelToHaveFocus( currentBlockLabel ); | ||
await pressKeyWithModifier( 'shift', 'Tab' ); | ||
await expectLabelToHaveFocus( 'Move up' ); | ||
} | ||
|
||
async function wrapCurrentBlockWithGroup() { | ||
await page.click( '[aria-label="Change block type or style"]' ); | ||
await page.evaluate( () => { | ||
document.querySelector( '.editor-block-list-item-group' ).click(); | ||
} ); | ||
} | ||
|
||
async function testGroupKeyboardNavigation( currentBlockLabel ) { | ||
await expectLabelToHaveFocus( 'Block: Group' ); | ||
await page.keyboard.press( 'Tab' ); | ||
await expectLabelToHaveFocus( currentBlockLabel ); | ||
await pressKeyWithModifier( 'shift', 'Tab' ); | ||
await expectLabelToHaveFocus( 'Select parent (Group)' ); | ||
await page.keyboard.press( 'ArrowRight' ); | ||
await expectLabelToHaveFocus( 'Change block type or style' ); | ||
} | ||
|
||
describe( 'Toolbar roving tabindex', () => { | ||
beforeEach( async () => { | ||
await createNewPost(); | ||
await insertBlock( 'Paragraph' ); | ||
await page.keyboard.type( 'First block' ); | ||
} ); | ||
|
||
it( 'ensures paragraph block toolbar uses roving tabindex', async () => { | ||
await insertBlock( 'Paragraph' ); | ||
await page.keyboard.type( 'Paragraph' ); | ||
await testBlockToolbarKeyboardNavigation( 'Paragraph block' ); | ||
await wrapCurrentBlockWithGroup(); | ||
await testGroupKeyboardNavigation( 'Paragraph block' ); | ||
} ); | ||
|
||
it( 'ensures heading block toolbar uses roving tabindex', async () => { | ||
await insertBlock( 'Heading' ); | ||
await page.keyboard.type( 'Heading' ); | ||
await testBlockToolbarKeyboardNavigation( 'Write heading…' ); | ||
await wrapCurrentBlockWithGroup(); | ||
await testGroupKeyboardNavigation( 'Write heading…' ); | ||
} ); | ||
|
||
it( 'ensures list block toolbar uses roving tabindex', async () => { | ||
await insertBlock( 'List' ); | ||
await page.keyboard.type( 'List' ); | ||
await testBlockToolbarKeyboardNavigation( 'Write list…' ); | ||
await wrapCurrentBlockWithGroup(); | ||
await testGroupKeyboardNavigation( 'Write list…' ); | ||
} ); | ||
|
||
it( 'ensures image block toolbar uses roving tabindex', async () => { | ||
await insertBlock( 'Image' ); | ||
await testBlockToolbarKeyboardNavigation( 'Block: Image' ); | ||
await wrapCurrentBlockWithGroup(); | ||
await testGroupKeyboardNavigation( 'Block: Image' ); | ||
} ); | ||
} ); |