diff --git a/packages/block-library/src/query/edit/index.js b/packages/block-library/src/query/edit/index.js
index ab75bdcaeb084d..84aaff2ff7f036 100644
--- a/packages/block-library/src/query/edit/index.js
+++ b/packages/block-library/src/query/edit/index.js
@@ -29,13 +29,14 @@ import { getFirstQueryClientIdFromBlocks } from '../utils';
const TEMPLATE = [ [ 'core/post-template' ] ];
-function ResetQueryLoopMenuItem( { clientId } ) {
- const selectedBlockClientId = useSelect(
- ( select ) => select( blockEditorStore ).getSelectedBlockClientId(),
- []
+function ResetQueryLoopMenuItem( { clientId, isSelected } ) {
+ const rootClientId = useSelect(
+ ( select ) =>
+ select( blockEditorStore ).getBlockRootClientId( clientId ),
+ [ clientId ]
);
const { replaceInnerBlocks } = useDispatch( blockEditorStore );
- if ( selectedBlockClientId !== clientId ) {
+ if ( ! isSelected || rootClientId ) {
return null;
}
return (
@@ -55,7 +56,12 @@ function ResetQueryLoopMenuItem( { clientId } ) {
);
}
-export function QueryContent( { attributes, setAttributes, clientId } ) {
+export function QueryContent( {
+ attributes,
+ setAttributes,
+ clientId,
+ isSelected,
+} ) {
const {
queryId,
query,
@@ -132,7 +138,10 @@ export function QueryContent( { attributes, setAttributes, clientId } ) {
setDisplayLayout={ updateDisplayLayout }
/>
-
+