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 v2]: Fix enter key action when the list is empty #44628

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 6 additions & 1 deletion packages/block-library/src/list-item/hooks/use-enter.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,14 @@ export default function useEnter( props ) {
} ),
]
: [];

// Replace the list block itself with a paragraph block if it's completely empty.
const isEmpty =
topParentListBlock.innerBlocks.length === 1 && ! content;

replaceBlocks(
topParentListBlock.clientId,
[ head, middle, ...tail ],
isEmpty ? [ middle ] : [ head, middle, ...tail ],
1
);
// We manually change the selection here because we are replacing
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/specs/editor/blocks/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,16 @@ test.describe( 'List', () => {
);
} );

test( 'Should be converted from an empty list to an empty paragraph block', async ( {
editor,
page,
} ) => {
await editor.insertBlock( { name: 'core/list' } );
await page.keyboard.press( 'Enter' );

await expect.poll( editor.getEditedPostContent ).toBe( `` );
} );

test( 'should split indented list item', async ( { editor, page } ) => {
await editor.insertBlock( { name: 'core/list' } );
await page.keyboard.type( 'one' );
Expand Down