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

List view: Allow selected block to override roving tabindex #48339

Merged
merged 6 commits into from
Feb 27, 2023
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
8 changes: 7 additions & 1 deletion packages/block-editor/src/components/list-view/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ function ListViewBlock( {
selectedClientIds,
} );

// Detect if there is a block in the canvas currently being edited and multi-selection is not happening.
const currentlyEditingBlockInCanvas =
isSelected && selectedClientIds.length === 1;

return (
<ListViewLeaf
className={ classes }
Expand Down Expand Up @@ -268,7 +272,9 @@ function ListViewBlock( {
siblingBlockCount={ siblingBlockCount }
level={ level }
ref={ ref }
tabIndex={ tabIndex }
tabIndex={
currentlyEditingBlockInCanvas ? 0 : tabIndex
}
onFocus={ onFocus }
isExpanded={ isExpanded }
selectedClientIds={ selectedClientIds }
Expand Down
56 changes: 55 additions & 1 deletion test/e2e/specs/editor/various/list-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test.describe( 'List View', () => {
] );

// Drag the paragraph above the heading.
const paragraphBlockItem = await listView.getByRole( 'gridcell', {
const paragraphBlockItem = listView.getByRole( 'gridcell', {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to remove this. ESLint would not allow me to commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

geyByRole doesn't return a promise so this is the right fix 👍 .

name: 'Paragraph link',
} );
const headingBlockItem = listView.getByRole( 'gridcell', {
Expand Down Expand Up @@ -507,4 +507,58 @@ test.describe( 'List View', () => {
await pageUtils.pressKeyWithModifier( 'access', 'o' );
await expect( listView ).not.toBeVisible();
} );

test( 'should place focus on the currently selected block in the canvas', async ( {
editor,
page,
pageUtils,
} ) => {
// Insert a couple of blocks of different types.
await editor.insertBlock( { name: 'core/image' } );
await editor.insertBlock( { name: 'core/heading' } );
await editor.insertBlock( { name: 'core/paragraph' } );

// Open List View.
await pageUtils.pressKeyWithModifier( 'access', 'o' );
const listView = page.getByRole( 'treegrid', {
name: 'Block navigation structure',
} );

// The last inserted block should be selected.
await expect(
listView.getByRole( 'gridcell', {
name: 'Paragraph link',
selected: true,
} )
).toBeVisible();

// Go to the image block in List View.
await pageUtils.pressKeyTimes( 'ArrowUp', 2 );
await expect(
listView
.getByRole( 'gridcell', {
name: 'Image link',
} )
.getByRole( 'link', { includeHidden: true } )
).toBeFocused();

// Select the image block in the canvas.
await page.keyboard.press( 'Enter' );
const imageBlock = editor.canvas.getByRole( 'document', {
name: 'Block: Image',
} );
await expect(
imageBlock.getByRole( 'button', { name: 'Upload' } )
).toBeFocused();

// Triggering the List View shortcut should result in the image block gaining focus.
await pageUtils.pressKeyWithModifier( 'access', 'o' );
await expect(
listView
.getByRole( 'gridcell', {
name: 'Image link',
} )
.getByRole( 'link', { includeHidden: true } )
).toBeFocused();
} );
} );