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: Fix home and end key behaviour in very long lists #62312

Merged
merged 2 commits into from
Jun 12, 2024
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
6 changes: 5 additions & 1 deletion packages/block-editor/src/components/list-view/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,14 @@ function ListViewBranch( props ) {
// This prevents the entire tree from being rendered when a branch is
// selected, or a user selects all blocks, while still enabling scroll
// into view behavior when selecting a block or opening the list view.
// The first and last blocks of the list are always rendered, to ensure
// that Home and End keys work as expected.
const showBlock =
isDragged ||
blockInView ||
( isSelected && clientId === selectedClientIds[ 0 ] );
( isSelected && clientId === selectedClientIds[ 0 ] ) ||
index === 0 ||
index === blockCount - 1;
return (
<AsyncModeProvider key={ clientId } value={ ! isSelected }>
{ showBlock && (
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/editor/various/list-view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ test.describe( 'List View', () => {
'Pressing keyboard shortcut should also work when the menu is opened and focused'
)
.toMatchObject( [
{ name: 'core/paragraph', selected: true, focused: false },
{ name: 'core/paragraph', selected: true, focused: true },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needed to be updated because it turns out this PR appears to resolve a subtle bug:

When you open the block settings menu dropdown for the last item in the list view and then use the insert before keyboard shortcut, prior to this PR, there's a tiny moment when the last block in the list evaluates to showBlock being false while blockInView is being recalculated. That render then appears to mean that the focus in list view behaviour fails, and so focus isn't kept within the list view.

With this PR, we now always render the last item in the list, so in this test we now (correctly) have focus redirected to the inserted block within the list view, which is the expected behaviour.

I believe how that's all working now, but I've only done a light investigation.

{ name: 'core/file', selected: false, focused: false },
] );
await expect(
Expand Down
Loading