Component badge for hidden block should display for all resolutions, not only Desktop
Description
This is related to issue #73776: WordPress 7.0: add option to hide blocks based on screen size.
The issue happens in the Editor for laptops/screens with low resolution or shrunk windows.
While technically being on a Desktop, if the user has a low-resolution screen or a small browser window, the component badge displaying on the right side leads to confusion.
The expected result is the badge to contain information about all the hidden states, instead of assuming the user is on a Desktop resolution.
Blocks that are visible on Desktop but hidden on Tablet/Mobile do not display any Component badge. So if the window is too narrowed and the user clicks a "Desktop-only" component, no info badge will be displayed for them.
Step-by-step reproduction instructions
- Make sure you're on WordPress 7.0 or above.
- Create a new page and add a paragraph that's Hidden on Mobile and Desktop (ie: tablet-only)
- Increase the resolution of your screen. Easiest way is to hit the keys
Cmd + +on your keyboard. Alternatively, edit the screen resolution on your computer, or reduce the size of your browser window. - Click your "tablet-only" block on the Editor
- You'll notice that a message saying that the "Block is hidden on Desktop". However, I can still see it, despite being on a "desktop"
Expected:
- The badge is very informative, but it should display for all blocks, not assume the user is on a Desktop-compatible resolution.
- It would be useful if badge also displays for Desktop-only blocks. Right now it only displays for tablet/mobile blocks.
Screenshots, screen recording, code snippet
Environment info
- WordPress 7.0
- Chrome
- MacOS
Please confirm that you have searched existing issues in the repo.
- [x] Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
- [x] Yes
Please confirm which theme type you used for testing.
- [x] Block
- [ ] Classic
- [ ] Hybrid (e.g. classic with theme.json)
- [ ] Not sure
Hi! I can take this up
Thank you for the issue.
I see... the badge is using the window viewport width and the blocks are using the canvas width.
Wondering if we can pass a ref useMediaQuery to get the canvas width. See for reference:
- https://github.com/WordPress/gutenberg/pull/76446
I'm thinking the same might have to be done for the tooltip on the eye icon in list view.
The challenge is that ViewportVisibilityInfo renders in the inspector (outside the canvas iframe), so it can't use the same useRefEffect + element.ownerDocument.defaultView approach.
Two potential approaches I can see:
- Store the canvas Window reference in the block editor store settings so the badge can read it
- Use
useViewportMatch.__experimentalWidthProviderto wrap the canvas with the simulated width context, which the badge could then consume
Given the direction in #75707 (theme-configurable breakpoints), would approach 2 fit better - or is there a cleaner way to expose the canvas window that I'm missing?
Something like this could work in the meantime?
- https://github.com/WordPress/gutenberg/pull/76889
I'm travelling so I'll have to do more testing.