Skip to content

Block Visibility: Show toggle option in the block inspector when responsive editing - #79995

Closed
talldan wants to merge 1 commit into
trunkfrom
surface/block-visibility-during-responsive-editing
Closed

talldan wants to merge 1 commit into
trunkfrom
surface/block-visibility-during-responsive-editing

Conversation

@talldan

@talldan talldan commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

What?

Shows a control in the block inspector that allows a user to easily toggle block visibility when responsive editing.

Why?

Viewport visibility allows hiding blocks on specific viewports, but until now it wasn't really connected at all to the new 'Responsive editing' option, which feels like a missing feature to me. The user has to open the viewport visibility modal which still displays options for every viewport, not the one selected.

How?

Adds a simple toggle for block visibility in a ToolsPanel that's shown whenever Responsive editing is enabled, and the user has tablet or mobile viewport selected.

Whether to show anything when 'Desktop' is selected is an open question. I personally think it's ok not to bother with that in a first iteration. Alternatively, an idea I had is that on desktop the UI could show toggles for all breakpoints (since the desktop option is considered as 'Edit across all breakpoints').

Testing Instructions

  1. Insert a block
  2. Enable 'Responsive editing' and select either mobile or tablet in the viewport dropdown
  3. Open the block inspector.
  4. Observe there's a 'Hide on Tablet / Mobile' toggle.
  5. Select it
  6. Observe the block is hidden.

Screenshots or screencast

Screenshot 2026-07-08 at 6 18 13 pm

Use of AI Tools

OpenCode / Codex

@talldan talldan self-assigned this Jul 8, 2026
@talldan
talldan requested a review from ellatrix as a code owner July 8, 2026 10:21
@talldan talldan added [Type] Enhancement A suggestion for improvement. [Feature] Inspector Controls The interface showing block settings and the controls available for each block [Feature] Style States Related to block style states (currently viewport and pseudo-states) labels Jul 8, 2026
@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Jul 8, 2026
<ViewportVisibilityInfo clientId={ renderedBlockClientId } />
{ ! isEditingStyleState && (
<ViewportVisibilityInfo clientId={ renderedBlockClientId } />
) }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to hide this info when the inspector control is shown, as otherwise it causes a layout shift whenever toggling to hide a block via the new control:
Image

Plus the info is already shown via the toggle. Possibly we could move it to below the toggle, but it might be too much.

@talldan talldan Jul 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a small issue though, the toggle has its own early return rendering logic that causes it to be not shown:

	if (
		! clientId ||
		! viewport ||
		! viewportLabel ||
		blockEditingMode !== 'default' ||
		blockVisibility === false ||
		! hasBlockSupport( blockName, 'visibility', true )
	) {
		return null;
	}

So in those cases the visibility info isn't shown but nor is the toggle. I'm looking at a fix for this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking out loud here, should we show the badge still if the block is hidden everywhere?

Maybe it's different to "responsive" editing because it's not rendered 🤔 I'm just wondering if a block is hidden everywhere and you enter responsive editing mode, if it'd be helpful to be able to toggle it off and apply viewport-specific rules.

Maybe a follow up.

@github-actions

github-actions Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@talldan
talldan requested a review from jasmussen July 8, 2026 10:24
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Size Change: +463 B (+0.01%)

Total Size: 7.67 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 418 kB +463 B (+0.11%)

compressed-size-action

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Flaky tests detected in c36c521.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/28935366625
📝 Reported issues:

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the following conditions match, neither the Block is hidden badge in the block inspector nor the Visibility panel is displayed, making it slightly unclear whether the block is hidden. Is this intended?

  • Select the Tablet viewport
  • Enable Resposive editing
  • Check "Omit from published content"
trunk This PR
Image Image

Comment on lines +57 to +62
const nextBlockVisibility = cleanEmptyObject( {
viewport: {
...blockVisibility?.viewport,
[ viewport ]: isHiddenOnViewport ? false : undefined,
},
} );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const nextBlockVisibility = cleanEmptyObject( {
viewport: {
...blockVisibility?.viewport,
[ viewport ]: isHiddenOnViewport ? false : undefined,
},
} );
const nextBlockVisibility = {
viewport: {
...blockVisibility?.viewport,
[ viewport ]: isHiddenOnViewport ? false : undefined,
},
};

Nit: This cleanEmptyObject seems redundant.

@tellthemachines

Copy link
Copy Markdown
Contributor

Just gave this a quick test run and noticed there seems to be a discrepancy between when "block is hidden in..." notice displays and the toggle shows in resizing from desktop to tablet:

toggle_visibility.mp4

Overall I'm not sure the toggle will be super useful, because hiding for a particular viewport is likely to be a flow where you hide one block on mobile and hide another version of the same block on tablet/desktop, so it might make more sense to do it all from the default "edit all breakpoints" view at once. Happy to be convinced otherwise though!

@ramonjd

ramonjd commented Jul 12, 2026

Copy link
Copy Markdown
Member

Whether to show anything when 'Desktop' is selected is an open question. I personally think it's ok not to bother with that in a first iteration. Alternatively, an idea I had is that on desktop the UI could show toggles for all breakpoints (since the desktop option is considered as 'Edit across all breakpoints').

Thanks for the PR. 100% agree it'd be great to have a way to connect visibility with responsive editing.

TBH I think the "desktop shows all three toggles" is consistent with "Desktop = overview/all breakpoints". I guess the cost is that we'd essentially rebuilt the modal inside the inspector.

@tellthemachines

Copy link
Copy Markdown
Contributor

I guess the cost is that we'd essentially rebuilt the modal inside the inspector.

The cost is also a large amount of block inspector real estate dedicated to a feature that isn't likely to be used very often. I'd hesitate to do this just for consistency, unless it's something we can add under an "advanced" tab or something.

@jasmussen

Copy link
Copy Markdown
Contributor

Apologies for the belated review. This seems a nice and simple improvement. What is the main feedback you are looking for? One thought that comes to mind is to show this at the bottom of the inspector, rather than at the top. Mostly to avoid layout shifts. But it's not strongly felt.

@tellthemachines

Copy link
Copy Markdown
Contributor

One thought that comes to mind is to show this at the bottom of the inspector,

That could work! I think we should reserve the top part to display more frequently used tools, which block visibility is very unlikely to be.

@talldan

talldan commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

This is too late now for 7.1, so lets put this on the backburner.

@talldan
talldan deleted the surface/block-visibility-during-responsive-editing branch October 28, 2026 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Inspector Controls The interface showing block settings and the controls available for each block [Feature] Style States Related to block style states (currently viewport and pseudo-states) [Package] Block editor /packages/block-editor [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants