Skip to content

Commit

Permalink
Avoid creating an empty paragraph when selecting the parent's group b…
Browse files Browse the repository at this point in the history
…lock (#21318)
  • Loading branch information
youknowriad authored Apr 1, 2020
1 parent 8aa3ad4 commit 307e1fb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ const BlockComponent = forwardRef(
const textInputs = focus.tabbable
.find( wrapper.current )
.filter( isTextField )
// Exclude inner blocks
.filter( ( node ) =>
isInsideRootBlock( wrapper.current, node )
// Exclude inner blocks and block appenders
.filter(
( node ) =>
isInsideRootBlock( wrapper.current, node ) &&
! node.closest( '.block-list-appender' )
);

// If reversed (e.g. merge via backspace), use the last in the set of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,15 @@ exports[`Navigating the block hierarchy should navigate using the block hierarch
<!-- /wp:column --></div>
<!-- /wp:columns -->"
`;
exports[`Navigating the block hierarchy should select the wrapper div for a group 1`] = `
"<!-- wp:group -->
<div class=\\"wp-block-group\\"><div class=\\"wp-block-group__inner-container\\"><!-- wp:paragraph -->
<p>just a paragraph</p>
<!-- /wp:paragraph -->
<!-- wp:separator -->
<hr class=\\"wp-block-separator\\"/>
<!-- /wp:separator --></div></div>
<!-- /wp:group -->"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,42 @@ describe( 'Navigating the block hierarchy', () => {

expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should select the wrapper div for a group ', async () => {
// Insert a group block
await insertBlock( 'Group' );

// Insert some random blocks.
// The last block shouldn't be a textual block.
await page.click( '.block-list-appender .block-editor-inserter' );
const paragraphMenuItem = (
await page.$x( `//button//span[contains(text(), 'Paragraph')]` )
)[ 0 ];
await paragraphMenuItem.click();
await page.keyboard.type( 'just a paragraph' );
await insertBlock( 'Separator' );

// Check the Group block content
expect( await getEditedPostContent() ).toMatchSnapshot();

// Unselect the blocks
await page.click( '.editor-post-title' );

// Try selecting the group block using the block navigation
await page.click( '[aria-label="Block navigation"]' );
const groupMenuItem = (
await page.$x(
"//button[contains(@class,'block-editor-block-navigation__item') and contains(text(), 'Group')]"
)
)[ 0 ];
await groupMenuItem.click();

// The group block's wrapper should be selected.
const isGroupBlockSelected = await page.evaluate(
() =>
document.activeElement.getAttribute( 'data-type' ) ===
'core/group'
);
expect( isGroupBlockSelected ).toBe( true );
} );
} );

0 comments on commit 307e1fb

Please sign in to comment.