@@ -16,6 +16,9 @@ import {
1616 GridItemResizer ,
1717 GridItemMovers ,
1818} from '../components/grid' ;
19+ import useBlockVisibility from '../components/block-visibility/use-block-visibility' ;
20+ import { deviceTypeKey } from '../store/private-keys' ;
21+ import { BLOCK_VISIBILITY_VIEWPORTS } from '../components/block-visibility/constants' ;
1922
2023// Used for generating the instance ID
2124const LAYOUT_CHILD_BLOCK_PROPS_REFERENCE = { } ;
@@ -199,12 +202,20 @@ function GridTools( {
199202 isManualPlacement,
200203 parentLayout,
201204} ) {
202- const { rootClientId, isVisible } = useSelect (
205+ const {
206+ rootClientId,
207+ isVisible,
208+ parentBlockVisibility,
209+ blockBlockVisibility,
210+ deviceType,
211+ } = useSelect (
203212 ( select ) => {
204213 const {
205214 getBlockRootClientId,
206215 getBlockEditingMode,
207216 getTemplateLock,
217+ getBlockAttributes,
218+ getSettings,
208219 } = select ( blockEditorStore ) ;
209220
210221 const _rootClientId = getBlockRootClientId ( clientId ) ;
@@ -219,21 +230,46 @@ function GridTools( {
219230 } ;
220231 }
221232
233+ const parentAttributes = getBlockAttributes ( _rootClientId ) ;
234+ const blockAttributes = getBlockAttributes ( clientId ) ;
235+ const settings = getSettings ( ) ;
236+
222237 return {
223238 rootClientId : _rootClientId ,
224239 isVisible : true ,
240+ parentBlockVisibility :
241+ parentAttributes ?. metadata ?. blockVisibility ,
242+ blockBlockVisibility :
243+ blockAttributes ?. metadata ?. blockVisibility ,
244+ deviceType :
245+ settings ?. [ deviceTypeKey ] ?. toLowerCase ( ) ||
246+ BLOCK_VISIBILITY_VIEWPORTS . desktop . value ,
225247 } ;
226248 } ,
227249 [ clientId ]
228250 ) ;
229251
252+ const { isBlockCurrentlyHidden : isParentBlockCurrentlyHidden } =
253+ useBlockVisibility ( {
254+ blockVisibility : parentBlockVisibility ,
255+ deviceType,
256+ } ) ;
257+
258+ const { isBlockCurrentlyHidden : isBlockItselfCurrentlyHidden } =
259+ useBlockVisibility ( {
260+ blockVisibility : blockBlockVisibility ,
261+ deviceType,
262+ } ) ;
263+
230264 // Use useState() instead of useRef() so that GridItemResizer updates when ref is set.
231265 const [ resizerBounds , setResizerBounds ] = useState ( ) ;
232266
233- if ( ! isVisible ) {
267+ if ( ! isVisible || isParentBlockCurrentlyHidden ) {
234268 return null ;
235269 }
236270
271+ const showResizer = allowSizingOnChildren && ! isBlockItselfCurrentlyHidden ;
272+
237273 function updateLayout ( layout ) {
238274 setAttributes ( {
239275 style : {
@@ -253,7 +289,7 @@ function GridTools( {
253289 contentRef = { setResizerBounds }
254290 parentLayout = { parentLayout }
255291 />
256- { allowSizingOnChildren && (
292+ { showResizer && (
257293 < GridItemResizer
258294 clientId = { clientId }
259295 // Don't allow resizing beyond the grid visualizer.
0 commit comments