Skip to content
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 @@ -115,9 +115,16 @@ export function getClosestTabbable(
}

function isTabCandidate( node ) {
// If it's a block and there are nested focusable nodes, skip because
// there are better candidates.
// If it's a block wrapper (not itself a contenteditable editing surface)
// and there are nested focusable nodes, skip because there are better
// candidates. We must not skip contenteditable nodes that happen to
// contain links or other focusable inline elements, since those are the
// correct navigation targets.
//
// See https://github.com/WordPress/gutenberg/pull/77474
// TODO: Consider fixing focus.tabbable
if (
node.contentEditable !== 'true' &&
getBlockClientId( node ) &&
focus.focusable
.find( node )
Expand Down
35 changes: 35 additions & 0 deletions test/e2e/specs/editor/various/writing-flow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,41 @@ test.describe( 'Writing Flow (@firefox, @webkit)', () => {
editor.canvas.getByRole( 'document', { name: 'Block: Paragraph' } )
).not.toBeFocused();
} );

// Regression test: ArrowDown should not skip over a paragraph that contains
// a link. See https://github.com/WordPress/gutenberg/issues/77473.
test( 'should not skip paragraph with link when navigating down with ArrowDown', async ( {
editor,
page,
} ) => {
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'a' },
} );
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: '<a href="#">a</a>' },
} );
await editor.insertBlock( {
name: 'core/paragraph',
attributes: { content: 'a' },
} );

// Position cursor at the start of the first paragraph.
await editor.canvas
.locator( 'role=document[name="Block: Paragraph"i]' )
.first()
.click();
await page.keyboard.press( 'Home' );

// ArrowDown should move to the second paragraph (with the link),
// not skip over it to the third.
await page.keyboard.press( 'ArrowDown' );

// The focused element should be the second paragraph, which contains a link.
const focusedElement = editor.canvas.locator( ':focus' );
await expect( focusedElement.locator( 'a[href="#"]' ) ).toBeVisible();
} );
} );

class WritingFlowUtils {
Expand Down
Loading