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

Fix tabbing from first or last block in site editor #42036

Merged
merged 3 commits into from
Jul 8, 2022
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
4 changes: 4 additions & 0 deletions packages/dom/src/dom/is-form-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import isInputOrTextArea from './is-input-or-text-area';
* @return {boolean} True if form element and false otherwise.
*/
export default function isFormElement( element ) {
if ( ! element ) {
return false;
}

const { tagName } = element;
const checkForInputTextarea = isInputOrTextArea( element );
return (
Expand Down
83 changes: 83 additions & 0 deletions test/e2e/specs/site-editor/writing-flow.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* WordPress dependencies
*/
const {
test,
expect,
Editor,
} = require( '@wordpress/e2e-test-utils-playwright' );

test.use( {
editor: async ( { page }, use ) => {
await use( new Editor( { page, hasIframe: true } ) );
},
} );

test.describe( 'Site editor writing flow', () => {
test.beforeAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'emptytheme' );
} );

test.afterAll( async ( { requestUtils } ) => {
await requestUtils.activateTheme( 'twentytwentyone' );
} );

// Check for regressions of https://github.com/WordPress/gutenberg/issues/41811.
test( 'allows shift tabbing to the block toolbar from the first block', async ( {
admin,
editor,
page,
pageUtils,
} ) => {
// Navigate to a template part with only a couple of blocks.
await admin.visitSiteEditor( {
postId: 'emptytheme//header',
postType: 'wp_template_part',
} );

// Select the first site title block.
const siteTitleBlock = editor.canvas.locator(
'role=document[name="Block: Site Title"i]'
);
await expect( siteTitleBlock ).toBeVisible();
await editor.selectBlocks( siteTitleBlock );

// Shift tab to the toolbar.
await pageUtils.pressKeyWithModifier( 'shift', 'Tab' );
const blockToolbarButton = page.locator(
'role=toolbar[name="Block tools"i] >> role=button[name="Site Title"i]'
);
await expect( blockToolbarButton ).toBeFocused();
} );

// Check for regressions of https://github.com/WordPress/gutenberg/issues/41811.
test( 'allows tabbing to the inspector from the last block', async ( {
admin,
editor,
page,
pageUtils,
} ) => {
// Navigate to a template part with only a couple of blocks.
await admin.visitSiteEditor( {
postId: 'emptytheme//header',
postType: 'wp_template_part',
} );

// Make sure the sidebar is open.
await editor.openDocumentSettingsSidebar();

// Select the last site tagline block.
const siteTaglineBlock = editor.canvas.locator(
'role=document[name="Block: Site Tagline"i]'
);
await expect( siteTaglineBlock ).toBeVisible();
await editor.selectBlocks( siteTaglineBlock );

// Tab to the inspector, tabbing three times to go past the two resize handles.
await pageUtils.pressKeyTimes( 'Tab', 3 );
const inspectorTemplateTab = page.locator(
'role=region[name="Editor settings"i] >> role=button[name="Template"i]'
);
await expect( inspectorTemplateTab ).toBeFocused();
} );
} );