[CYS - Full Composability] Select the next block after deleting the selected one (#48316)

* Select the next block after deleting one

* Add changefile(s) from automation for the following project(s): woocommerce

* Fix lint error

* Check if next block client is defined

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Alba Rincón 2024-06-10 14:33:32 +02:00 committed by GitHub
parent ccbb811d7d
commit 9d114c6d2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 3 deletions

View File

@ -10,9 +10,15 @@ import {
// @ts-expect-error missing type
} from '@wordpress/block-editor';
export default function Delete( { clientId }: { clientId: string } ) {
export default function Delete( {
clientId,
nextBlockClientId,
}: {
clientId: string;
nextBlockClientId: string | undefined;
} ) {
// @ts-expect-error missing type
const { removeBlock } = useDispatch( blockEditorStore );
const { removeBlock, selectBlock } = useDispatch( blockEditorStore );
return (
<ToolbarGroup>
@ -22,6 +28,9 @@ export default function Delete( { clientId }: { clientId: string } ) {
icon={ trash }
onClick={ () => {
removeBlock( clientId );
if ( nextBlockClientId ) {
selectBlock( nextBlockClientId );
}
} }
/>
</ToolbarButton>

View File

@ -144,7 +144,10 @@ export const Toolbar = () => {
/>
</ToolbarGroup>
<Shuffle clientId={ selectedBlockClientId } />
<Delete clientId={ selectedBlockClientId } />
<Delete
clientId={ selectedBlockClientId }
nextBlockClientId={ nextBlock?.clientId }
/>
</>
</WPToolbar>
</div>

View File

@ -0,0 +1,4 @@
Significance: minor
Type: fix
CYS - Select the next block after deleting the selected one (instead of the header).