From 7631549a468cfd4cd4a408380520af0edf0280a6 Mon Sep 17 00:00:00 2001 From: Derek Blank Date: Fri, 16 Jun 2023 10:40:11 +1000 Subject: [PATCH] [RNMobile] Fix crash when using the delete key to remove a single button (#51435) * Fix crash when using the delete key to remove a single button * Add onDeleteBlock prop to block.native.js * Update button edit.native.js snapshots * Update button delete test to focus button input * Update button test to use triggerBlockListLayout --- .../src/components/block-list/block.native.js | 1 + .../test/__snapshots__/edit.native.js.snap | 6 +++++ .../src/buttons/test/edit.native.js | 27 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/packages/block-editor/src/components/block-list/block.native.js b/packages/block-editor/src/components/block-list/block.native.js index 41e166327ccca..bb537f22d0fb0 100644 --- a/packages/block-editor/src/components/block-list/block.native.js +++ b/packages/block-editor/src/components/block-list/block.native.js @@ -345,6 +345,7 @@ function BlockListBlock( { isSelectionEnabled={ isSelectionEnabled } mergeBlocks={ canRemove ? onMerge : undefined } name={ name } + onDeleteBlock={ onDeleteBlock } onFocus={ onFocus } onRemove={ canRemove ? onRemove : undefined } onReplace={ canRemove ? onReplace : undefined } diff --git a/packages/block-library/src/buttons/test/__snapshots__/edit.native.js.snap b/packages/block-library/src/buttons/test/__snapshots__/edit.native.js.snap index 1a55c807225d9..25867634d12d8 100644 --- a/packages/block-library/src/buttons/test/__snapshots__/edit.native.js.snap +++ b/packages/block-library/src/buttons/test/__snapshots__/edit.native.js.snap @@ -71,3 +71,9 @@ exports[`Buttons block when a button is shown removing button along with buttons

" `; + +exports[`Buttons block when a button is shown removing button along with buttons block removes the button and buttons block when deleting the block using the delete (backspace) key 1`] = ` +" +

+" +`; diff --git a/packages/block-library/src/buttons/test/edit.native.js b/packages/block-library/src/buttons/test/edit.native.js index 5ba97e7bb4caf..ade014330a1b2 100644 --- a/packages/block-library/src/buttons/test/edit.native.js +++ b/packages/block-library/src/buttons/test/edit.native.js @@ -18,6 +18,7 @@ import { */ import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks'; import { registerCoreBlocks } from '@wordpress/block-library'; +import { BACKSPACE } from '@wordpress/keycodes'; const BUTTONS_HTML = `
@@ -232,6 +233,32 @@ describe( 'Buttons block', () => { expect( getEditorHtml() ).toMatchSnapshot(); } ); + + it( 'removes the button and buttons block when deleting the block using the delete (backspace) key', async () => { + const screen = await initializeEditor( { + initialHtml: BUTTONS_HTML, + } ); + + // Get block + const buttonsBlock = await getBlock( screen, 'Buttons' ); + triggerBlockListLayout( buttonsBlock ); + + // Get inner button block + const buttonBlock = await getBlock( screen, 'Button' ); + fireEvent.press( buttonBlock ); + + const buttonInput = + within( buttonBlock ).getByLabelText( 'Text input. Empty' ); + + // Delete block + fireEvent( buttonInput, 'onKeyDown', { + nativeEvent: {}, + preventDefault() {}, + keyCode: BACKSPACE, + } ); + + expect( getEditorHtml() ).toMatchSnapshot(); + } ); } ); } );