Skip to content

Commit

Permalink
[RNMobile] Fix crash when using the delete key to remove a single but…
Browse files Browse the repository at this point in the history
…ton (#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
  • Loading branch information
derekblank authored and fluiddot committed Jun 16, 2023
1 parent 64e6ebf commit 7631549
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ exports[`Buttons block when a button is shown removing button along with buttons
<p></p>
<!-- /wp:paragraph -->"
`;

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`] = `
"<!-- wp:paragraph -->
<p></p>
<!-- /wp:paragraph -->"
`;
27 changes: 27 additions & 0 deletions packages/block-library/src/buttons/test/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<!-- wp:buttons -->
<div class="wp-block-buttons"><!-- wp:button /--></div>
Expand Down Expand Up @@ -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();
} );
} );
} );

Expand Down

0 comments on commit 7631549

Please sign in to comment.