gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Component badge for hidden block should display for all resolutions, not only Desktop

Open ecairol opened this issue 8 months ago • 4 comments

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

  1. Make sure you're on WordPress 7.0 or above.
  2. Create a new page and add a paragraph that's Hidden on Mobile and Desktop (ie: tablet-only)
  3. 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.
  4. Click your "tablet-only" block on the Editor
  5. 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

Image

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

ecairol avatar Mar 20 '26 16:03 ecairol

Hi! I can take this up

Swanand01 avatar Mar 23 '26 07:03 Swanand01

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.

ramonjd avatar Mar 24 '26 05:03 ramonjd

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:

  1. Store the canvas Window reference in the block editor store settings so the badge can read it
  2. Use useViewportMatch.__experimentalWidthProvider to 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?

Swanand01 avatar Mar 26 '26 08:03 Swanand01

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.

ramonjd avatar Mar 29 '26 08:03 ramonjd