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 5 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
@@ -1,10 +1,5 @@
.block-editor-block-parent-selector {
background: $white;

.block-editor-block-parent-selector__button {
width: $grid-unit-60;
height: $grid-unit-60;
border: $border-width solid $dark-gray-primary;
border-radius: $radius-block-ui;
}
border: $border-width solid $dark-gray-primary;
border-radius: $radius-block-ui;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* 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 testToolbar( currentBlockLabel ) {
diegohaz marked this conversation as resolved.
Show resolved Hide resolved
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 testGroup( currentBlockLabel ) {
await page.click( '[aria-label="Change block type or style"]' );
await page.evaluate( () => {
document.querySelector( '.editor-block-list-item-group' ).click();
} );
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 testToolbar( 'Paragraph block' );
await testGroup( 'Paragraph block' );
} );

it( 'ensures heading block toolbar uses roving tabindex', async () => {
await insertBlock( 'Heading' );
await page.keyboard.type( 'Heading' );
await testToolbar( 'Write heading…' );
await testGroup( 'Write heading…' );
} );

it( 'ensures list block toolbar uses roving tabindex', async () => {
await insertBlock( 'List' );
await page.keyboard.type( 'List' );
await testToolbar( 'Write list…' );
await testGroup( 'Write list…' );
} );

it( 'ensures image block toolbar uses roving tabindex', async () => {
await insertBlock( 'Image' );
await testToolbar( 'Block: Image' );
await testGroup( 'Block: Image' );
} );
} );