Skip to content

Commit c47e155

Browse files
Fix inserting button block when pressing enter in a block with bound text attribute (#59361)
* Add tabindex 0 to all disabled elements in rich text * Insert block when use enter in disabled rich text * Take default block into account * Add e2e tests when pressing enter in bound blocks * Revert initial implementation * Use `insertAfterBlock` instead of `insertDefaultBlock`. * Remove unnecessary `insertDefaultBlock` * Destructure innerBlocks array in tests Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl> * Prettify tests * Remove unnecessary select in tests * Destructuring blocks in tests * Revert "Remove unnecessary select in tests" This reverts commit 63ffff87ca048a218567772710dcc45affcfd2aa. * Remove unnecessary select in tests * Adapt tests to latest changes --------- Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>
1 parent 8c77df8 commit c47e155

2 files changed

Lines changed: 184 additions & 69 deletions

File tree

packages/block-editor/src/components/block-list/use-block-props/use-selected-block-event-handlers.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { store as blockEditorStore } from '../../../store';
2222
export function useEventHandlers( { clientId, isSelected } ) {
2323
const { getBlockRootClientId, getBlockIndex } =
2424
useSelect( blockEditorStore );
25-
const { insertDefaultBlock, removeBlock } = useDispatch( blockEditorStore );
25+
const { insertAfterBlock, removeBlock } = useDispatch( blockEditorStore );
2626

2727
return useRefEffect(
2828
( node ) => {
@@ -57,11 +57,7 @@ export function useEventHandlers( { clientId, isSelected } ) {
5757
event.preventDefault();
5858

5959
if ( keyCode === ENTER ) {
60-
insertDefaultBlock(
61-
{},
62-
getBlockRootClientId( clientId ),
63-
getBlockIndex( clientId ) + 1
64-
);
60+
insertAfterBlock( clientId );
6561
} else {
6662
removeBlock( clientId );
6763
}
@@ -90,7 +86,7 @@ export function useEventHandlers( { clientId, isSelected } ) {
9086
isSelected,
9187
getBlockRootClientId,
9288
getBlockIndex,
93-
insertDefaultBlock,
89+
insertAfterBlock,
9490
removeBlock,
9591
]
9692
);

0 commit comments

Comments
 (0)