From ba95eef4b08e027f9c56d30afdc1eb8486f75732 Mon Sep 17 00:00:00 2001 From: Nick Diego Date: Fri, 26 Aug 2022 10:47:51 -0500 Subject: [PATCH 1/2] Prevent single Columns blocks transforming into Columns. --- .../block-library/src/columns/transforms.js | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/columns/transforms.js b/packages/block-library/src/columns/transforms.js index cef6bd32794e0..25a8c37582200 100644 --- a/packages/block-library/src/columns/transforms.js +++ b/packages/block-library/src/columns/transforms.js @@ -29,9 +29,23 @@ const transforms = { createBlocksFromInnerBlocksTemplate( innerBlocksTemplate ) ); }, - isMatch: ( { length: selectedBlocksLength } ) => - selectedBlocksLength && - selectedBlocksLength <= MAXIMUM_SELECTED_BLOCKS, + isMatch: ( { length: selectedBlocksLength }, block ) => { + // If a user is trying to transform a single Columns block, skip + // the transformation. Enabling this functiontionality creates + // nested Columns blocks resulting in an unintuitive user experience. + // Multiple Columns blocks can still be transformed. + if ( + block.length === 1 && + block[ 0 ].name === 'core/columns' + ) { + return false; + } + + return ( + selectedBlocksLength && + selectedBlocksLength <= MAXIMUM_SELECTED_BLOCKS + ); + }, }, { type: 'block', From 05f568f30534d2bfd5bbd050994a19249e1f912f Mon Sep 17 00:00:00 2001 From: Nick Diego Date: Fri, 26 Aug 2022 11:02:49 -0500 Subject: [PATCH 2/2] Change name to be more consistent. --- packages/block-library/src/columns/transforms.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/block-library/src/columns/transforms.js b/packages/block-library/src/columns/transforms.js index 25a8c37582200..9fb80e49e4295 100644 --- a/packages/block-library/src/columns/transforms.js +++ b/packages/block-library/src/columns/transforms.js @@ -29,14 +29,14 @@ const transforms = { createBlocksFromInnerBlocksTemplate( innerBlocksTemplate ) ); }, - isMatch: ( { length: selectedBlocksLength }, block ) => { + isMatch: ( { length: selectedBlocksLength }, blocks ) => { // If a user is trying to transform a single Columns block, skip // the transformation. Enabling this functiontionality creates // nested Columns blocks resulting in an unintuitive user experience. // Multiple Columns blocks can still be transformed. if ( - block.length === 1 && - block[ 0 ].name === 'core/columns' + blocks.length === 1 && + blocks[ 0 ].name === 'core/columns' ) { return false; }