Skip to content

Commit

Permalink
Fix inserting button block when pressing enter in a block with bound …
Browse files Browse the repository at this point in the history
…`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>
  • Loading branch information
SantosGuillamot and gziolo authored Mar 1, 2024
1 parent 8c77df8 commit c47e155
Show file tree
Hide file tree
Showing 2 changed files with 184 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { store as blockEditorStore } from '../../../store';
export function useEventHandlers( { clientId, isSelected } ) {
const { getBlockRootClientId, getBlockIndex } =
useSelect( blockEditorStore );
const { insertDefaultBlock, removeBlock } = useDispatch( blockEditorStore );
const { insertAfterBlock, removeBlock } = useDispatch( blockEditorStore );

return useRefEffect(
( node ) => {
Expand Down Expand Up @@ -57,11 +57,7 @@ export function useEventHandlers( { clientId, isSelected } ) {
event.preventDefault();

if ( keyCode === ENTER ) {
insertDefaultBlock(
{},
getBlockRootClientId( clientId ),
getBlockIndex( clientId ) + 1
);
insertAfterBlock( clientId );
} else {
removeBlock( clientId );
}
Expand Down Expand Up @@ -90,7 +86,7 @@ export function useEventHandlers( { clientId, isSelected } ) {
isSelected,
getBlockRootClientId,
getBlockIndex,
insertDefaultBlock,
insertAfterBlock,
removeBlock,
]
);
Expand Down
Loading

0 comments on commit c47e155

Please sign in to comment.