diff --git a/docs/designers-developers/developers/data/data-core-block-editor.md b/docs/designers-developers/developers/data/data-core-block-editor.md index b4e3f2cd31a4ad..3d058878226baa 100644 --- a/docs/designers-developers/developers/data/data-core-block-editor.md +++ b/docs/designers-developers/developers/data/data-core-block-editor.md @@ -1250,7 +1250,7 @@ _Parameters_ - _rootClientId_ `string`: Client ID of the block whose InnerBlocks will re replaced. - _blocks_ `Array`: Block objects to insert as new InnerBlocks -- _updateSelection_ `?boolean`: If true block selection will be updated. If false, block selection will not change. Defaults to true. +- _updateSelection_ `?boolean`: If true block selection will be updated. If false, block selection will not change. Defaults to false. _Returns_ diff --git a/packages/block-editor/src/components/block-variation-picker/index.native.js b/packages/block-editor/src/components/block-variation-picker/index.native.js index eba775e09f278f..f7029dc00acce4 100644 --- a/packages/block-editor/src/components/block-variation-picker/index.native.js +++ b/packages/block-editor/src/components/block-variation-picker/index.native.js @@ -68,8 +68,7 @@ function BlockVariationPicker( { isVisible, onClose, clientId, variations } ) { const onVariationSelect = ( variation ) => { replaceInnerBlocks( clientId, - createBlocksFromInnerBlocksTemplate( variation.innerBlocks ), - false + createBlocksFromInnerBlocksTemplate( variation.innerBlocks ) ); onClose(); }; diff --git a/packages/block-editor/src/components/inner-blocks/README.md b/packages/block-editor/src/components/inner-blocks/README.md index 4cdd0e9b5ffd3e..0c4a9ae1b40539 100644 --- a/packages/block-editor/src/components/inner-blocks/README.md +++ b/packages/block-editor/src/components/inner-blocks/README.md @@ -102,7 +102,7 @@ The previous example creates an InnerBlocks area containing two columns one with ### `templateInsertUpdatesSelection` * **Type:** `Boolean` -* **Default:** `true` +* **Default:** `false` If true when child blocks in the template are inserted the selection is updated. If false the selection should not be updated when child blocks specified in the template are inserted. diff --git a/packages/block-editor/src/components/provider/test/use-block-sync.js b/packages/block-editor/src/components/provider/test/use-block-sync.js index 583d50f3547ad8..5d42ab62929610 100644 --- a/packages/block-editor/src/components/provider/test/use-block-sync.js +++ b/packages/block-editor/src/components/provider/test/use-block-sync.js @@ -97,8 +97,7 @@ describe( 'useBlockSync hook', () => { expect( onInput ).not.toHaveBeenCalled(); expect( replaceInnerBlocks ).toHaveBeenCalledWith( 'test', // It should use the given client ID. - fakeBlocks, // It should use the controlled blocks value. - false // It shoudl not update the selection state. + fakeBlocks // It should use the controlled blocks value. ); const testBlocks = [ @@ -119,11 +118,7 @@ describe( 'useBlockSync hook', () => { expect( onChange ).not.toHaveBeenCalled(); expect( onInput ).not.toHaveBeenCalled(); expect( resetBlocks ).not.toHaveBeenCalled(); - expect( replaceInnerBlocks ).toHaveBeenCalledWith( - 'test', - testBlocks, - false - ); + expect( replaceInnerBlocks ).toHaveBeenCalledWith( 'test', testBlocks ); } ); it( 'does not add the controlled blocks to the block-editor store if the store already contains them', async () => { @@ -315,7 +310,7 @@ describe( 'useBlockSync hook', () => { ); } ); - expect( replaceInnerBlocks ).toHaveBeenCalledWith( 'test', [], false ); + expect( replaceInnerBlocks ).toHaveBeenCalledWith( 'test', [] ); expect( onChange ).not.toHaveBeenCalled(); expect( onInput ).not.toHaveBeenCalled(); } ); diff --git a/packages/block-editor/src/components/provider/use-block-sync.js b/packages/block-editor/src/components/provider/use-block-sync.js index cf07c062b46b43..6a2f04c3f86b7c 100644 --- a/packages/block-editor/src/components/provider/use-block-sync.js +++ b/packages/block-editor/src/components/provider/use-block-sync.js @@ -96,7 +96,7 @@ export default function useBlockSync( { if ( clientId ) { setHasControlledInnerBlocks( clientId, true ); __unstableMarkNextChangeAsNotPersistent(); - replaceInnerBlocks( clientId, controlledBlocks, false ); + replaceInnerBlocks( clientId, controlledBlocks ); } else { resetBlocks( controlledBlocks ); } diff --git a/packages/block-editor/src/store/actions.js b/packages/block-editor/src/store/actions.js index 0bedccade322db..01c61957f26d32 100644 --- a/packages/block-editor/src/store/actions.js +++ b/packages/block-editor/src/store/actions.js @@ -661,14 +661,14 @@ export function removeBlock( clientId, selectPrevious ) { * * @param {string} rootClientId Client ID of the block whose InnerBlocks will re replaced. * @param {Object[]} blocks Block objects to insert as new InnerBlocks - * @param {?boolean} updateSelection If true block selection will be updated. If false, block selection will not change. Defaults to true. + * @param {?boolean} updateSelection If true block selection will be updated. If false, block selection will not change. Defaults to false. * * @return {Object} Action object. */ export function replaceInnerBlocks( rootClientId, blocks, - updateSelection = true + updateSelection = false ) { return { type: 'REPLACE_INNER_BLOCKS', diff --git a/packages/block-editor/src/store/test/actions.js b/packages/block-editor/src/store/test/actions.js index dc7ad96e3261a7..47be32b9037765 100644 --- a/packages/block-editor/src/store/test/actions.js +++ b/packages/block-editor/src/store/test/actions.js @@ -1100,17 +1100,17 @@ describe( 'actions', () => { blocks: [ block ], rootClientId: 'root', time: expect.any( Number ), - updateSelection: true, + updateSelection: false, } ); } ); - it( 'should return the REPLACE_INNER_BLOCKS action with updateSelection false', () => { - expect( replaceInnerBlocks( 'root', [ block ], false ) ).toEqual( { + it( 'should return the REPLACE_INNER_BLOCKS action with updateSelection true', () => { + expect( replaceInnerBlocks( 'root', [ block ], true ) ).toEqual( { type: 'REPLACE_INNER_BLOCKS', blocks: [ block ], rootClientId: 'root', time: expect.any( Number ), - updateSelection: false, + updateSelection: true, } ); } ); } ); diff --git a/packages/block-library/src/buttons/edit.js b/packages/block-library/src/buttons/edit.js index a77f1bf335fd5c..e65ec7b804ad2b 100644 --- a/packages/block-library/src/buttons/edit.js +++ b/packages/block-library/src/buttons/edit.js @@ -39,6 +39,7 @@ function ButtonsEdit( { type: 'default', alignments: [], }, + templateInsertUpdatesSelection: true, } ); return ( <> diff --git a/packages/block-library/src/buttons/edit.native.js b/packages/block-library/src/buttons/edit.native.js index b190907b7b1eeb..1cbd6804df008c 100644 --- a/packages/block-library/src/buttons/edit.native.js +++ b/packages/block-library/src/buttons/edit.native.js @@ -137,6 +137,7 @@ export default function ButtonsEdit( { marginHorizontal={ spacing } marginVertical={ spacing } __experimentalLayout={ { type: 'default', alignments: [] } } + templateInsertUpdatesSelection /> ); diff --git a/packages/block-library/src/columns/edit.js b/packages/block-library/src/columns/edit.js index c5addd9a891ee3..1238883851e6d5 100644 --- a/packages/block-library/src/columns/edit.js +++ b/packages/block-library/src/columns/edit.js @@ -195,7 +195,7 @@ const ColumnsEditContainerWrapper = withDispatch( } } - replaceInnerBlocks( clientId, innerBlocks, false ); + replaceInnerBlocks( clientId, innerBlocks ); }, } ) )( ColumnsEditContainer ); @@ -235,7 +235,8 @@ function Placeholder( { clientId, name, setAttributes } ) { clientId, createBlocksFromInnerBlocksTemplate( nextVariation.innerBlocks - ) + ), + true ); } } } diff --git a/packages/block-library/src/columns/edit.native.js b/packages/block-library/src/columns/edit.native.js index 1e5e61bea8d9a9..d1aaa9441a90e1 100644 --- a/packages/block-library/src/columns/edit.native.js +++ b/packages/block-library/src/columns/edit.native.js @@ -311,7 +311,7 @@ const ColumnsEditContainerWrapper = withDispatch( ); } - replaceInnerBlocks( clientId, innerBlocks, false ); + replaceInnerBlocks( clientId, innerBlocks ); }, onAddNextColumn: () => { const { clientId } = ownProps; diff --git a/packages/block-library/src/cover/edit.js b/packages/block-library/src/cover/edit.js index f81c04382debf9..e75e474a655acc 100644 --- a/packages/block-library/src/cover/edit.js +++ b/packages/block-library/src/cover/edit.js @@ -453,7 +453,10 @@ function CoverEdit( { { className: 'wp-block-cover__inner-container', }, - { template: INNER_BLOCKS_TEMPLATE } + { + template: INNER_BLOCKS_TEMPLATE, + templateInsertUpdatesSelection: true, + } ); if ( ! hasBackground ) { diff --git a/packages/block-library/src/cover/edit.native.js b/packages/block-library/src/cover/edit.native.js index ee9f7c86e7f03a..3bc9c38c873516 100644 --- a/packages/block-library/src/cover/edit.native.js +++ b/packages/block-library/src/cover/edit.native.js @@ -514,7 +514,10 @@ const Cover = ( { pointerEvents="box-none" style={ [ styles.content, { minHeight: CONTAINER_HEIGHT } ] } > - + diff --git a/packages/block-library/src/media-text/edit.js b/packages/block-library/src/media-text/edit.js index a837b246fd2352..fb9381ddb6a623 100644 --- a/packages/block-library/src/media-text/edit.js +++ b/packages/block-library/src/media-text/edit.js @@ -286,13 +286,8 @@ function MediaTextEdit( { attributes, isSelected, setAttributes } ) { } ); const innerBlocksProps = useInnerBlocksProps( - { - className: 'wp-block-media-text__content', - }, - { - template: TEMPLATE, - templateInsertUpdatesSelection: false, - } + { className: 'wp-block-media-text__content' }, + { template: TEMPLATE } ); return ( diff --git a/packages/block-library/src/media-text/edit.native.js b/packages/block-library/src/media-text/edit.native.js index 3eaab4e09988fb..f6ad9cf9fdbc43 100644 --- a/packages/block-library/src/media-text/edit.native.js +++ b/packages/block-library/src/media-text/edit.native.js @@ -379,10 +379,7 @@ class MediaTextEdit extends Component { ...innerBlockContainerStyle, } } > - + diff --git a/packages/block-library/src/navigation/edit.js b/packages/block-library/src/navigation/edit.js index 6822883685f101..0cfb54aa8b46fe 100644 --- a/packages/block-library/src/navigation/edit.js +++ b/packages/block-library/src/navigation/edit.js @@ -69,7 +69,6 @@ function Navigation( { isSelected ? InnerBlocks.DefaultAppender : false, - templateInsertUpdatesSelection: false, __experimentalAppenderTagName: 'li', __experimentalCaptureToolbars: true, // Template lock set to false here so that the Nav @@ -214,7 +213,8 @@ export default compose( [ } dispatch( 'core/block-editor' ).replaceInnerBlocks( clientId, - blocks + blocks, + true ); }, }; diff --git a/packages/block-library/src/query-loop/edit.js b/packages/block-library/src/query-loop/edit.js index 6f14b7dd71a4ab..a5aa897994d75c 100644 --- a/packages/block-library/src/query-loop/edit.js +++ b/packages/block-library/src/query-loop/edit.js @@ -122,10 +122,7 @@ export default function QueryLoopEdit( { > { blockContext === ( activeBlockContext || blockContexts[ 0 ] ) ? ( - + ) : (
- +
diff --git a/packages/e2e-tests/plugins/block-context/index.js b/packages/e2e-tests/plugins/block-context/index.js index 0bca6a508074e7..cfc233a927ac77 100644 --- a/packages/e2e-tests/plugins/block-context/index.js +++ b/packages/e2e-tests/plugins/block-context/index.js @@ -32,6 +32,7 @@ el( InnerBlocks, { template: [ [ 'gutenberg/test-context-consumer', {} ] ], templateLock: 'all', + templateInsertUpdatesSelection: true, } ) ); }, diff --git a/packages/e2e-tests/plugins/inner-blocks-templates/index.js b/packages/e2e-tests/plugins/inner-blocks-templates/index.js index e6897e4b7d9500..8658bac1b47027 100644 --- a/packages/e2e-tests/plugins/inner-blocks-templates/index.js +++ b/packages/e2e-tests/plugins/inner-blocks-templates/index.js @@ -1,4 +1,4 @@ -( function() { +( function () { var registerBlockType = wp.blocks.registerBlockType; var createBlock = wp.blocks.createBlock; var el = wp.element.createElement; @@ -24,7 +24,7 @@ ], ]; - var save = function() { + var save = function () { return el( InnerBlocks.Content ); }; @@ -33,7 +33,7 @@ icon: 'cart', category: 'text', - edit: function( props ) { + edit: function ( props ) { return el( InnerBlocks, { template: TEMPLATE, } ); @@ -47,7 +47,7 @@ icon: 'cart', category: 'text', - edit: function( props ) { + edit: function ( props ) { return el( InnerBlocks, { template: TEMPLATE, templateLock: 'all', @@ -62,9 +62,10 @@ icon: 'cart', category: 'text', - edit: function( props ) { + edit: function ( props ) { return el( InnerBlocks, { template: TEMPLATE_PARAGRAPH_PLACEHOLDER, + templateInsertUpdatesSelection: true, } ); }, @@ -86,7 +87,7 @@ 'test/test-inner-blocks-locking-all', 'test/test-inner-blocks-paragraph-placeholder', ], - transform: function( attributes, innerBlocks ) { + transform: function ( attributes, innerBlocks ) { return createBlock( 'test/test-inner-blocks-transformer-target', attributes, @@ -99,7 +100,7 @@ { type: 'block', blocks: [ 'test/i-dont-exist' ], - transform: function( attributes, innerBlocks ) { + transform: function ( attributes, innerBlocks ) { return createBlock( 'test/test-inner-blocks-transformer-target', attributes, @@ -110,7 +111,7 @@ ], }, - edit: function( props ) { + edit: function ( props ) { return el( InnerBlocks, { template: TEMPLATE, } );