Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement roving tabindex on grouped blocks toolbars #23216

Merged
merged 7 commits into from
Jun 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { getBlockType } from '@wordpress/blocks';
import { Button } from '@wordpress/components';
import { ToolbarButton } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';

Expand Down Expand Up @@ -41,7 +41,7 @@ export default function BlockParentSelector() {
className="block-editor-block-parent-selector"
key={ firstParentClientId }
>
<Button
<ToolbarButton
className="block-editor-block-parent-selector__button"
onClick={ () => selectBlock( firstParentClientId ) }
label={ sprintf(
Expand Down
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' );
} );
} );