Replies: 9 comments 14 replies
-
A couple of thoughts, I like the sound of this.
For the "breakpoints visibility". This is a cool feature but It has hidden complexities that we need to understand and tackle first. If I'm not wrong, we don't have any support for breakpoints in any of the blocks (frontend). This has a few implications:
|
Beta Was this translation helpful? Give feedback.
-
You say this, but I can actually see it being merged and extremely useful in it's entirity. |
Beta Was this translation helpful? Give feedback.
-
Having this shipped as a UI primitive is super interesting as we're exploring this in WooCommerce as well. We have several blocks in our Checkout block that are conditionally rendered, but it makes it very hard to communicate that in the editor. Us, or developer, would choose to always render them in the editor, or never render them. Figuring our how a hidden block should be communicated, and also, a conditionally hidden block. On a code level, we're looking to allow developer to show/hide fields in the Checkout conditionally (right now via writing a JSON schema), and would love to see how this matures to the editor. I'd expect that developers should be able to write the same "syntax" that the editor UI would output. |
Beta Was this translation helpful? Give feedback.
-
Thank you for starting the conversation on this. In the Block Editor, there are often a handful of ways to accomplish a specific look or layout. If I'm in the List View and want to compare solutions or see what a group or pattern looks like without a block, it requires me to remove the blocks altogether, removing any of the customizations along with them. Being able to Show or Hide blocks in the List View by clicking an Eye icon similar to Photoshop with layers is all I'm looking for. |
Beta Was this translation helpful? Give feedback.
-
There's obviously a lot of us who just say "merge it all" and if not, then "make canonical plugins a real thing" so advanced users can quickly enable settings like these without leaving the editor. But I understand that's a pipe dream and probably not a realistic solution anyway. It's currently a plugin and it works very well! So my question for @ndiego is: what would merging this plugin into core mean for it's functionality? What can you currently not accomplish because this is a plugin and not a core feature of Gutenberg? That might change what parts get merged and what parts don't or are first built as distinct, extensible API components. |
Beta Was this translation helpful? Give feedback.
-
I would echo @bacoords that a lot of the I would also suggest that we consider conditionals based on post meta. This becomes powerful to say "Display this heading block only when post meta X has a value", effectively making the heading block a label for a paragraph displaying a meta field using Block Bindings. Again, super powerful when building site editor templates that are reusable. I can't find it right now, but there is an open issue requesting the ability to add a prefix/postfix content to blocks using the Block Bindings API. I think this would be a better solution. The Meta Block Field does this via pre/post text fields, but its quite limiting in formatting and overall control rather than doing this via blocks. I would also agree that leaving a lot to plugins makes sense. Any underlying API could allow, for example, ACF to add their own conditions based on their values. Similar to the Block Bindings API. Not mentioned here yet: I also use Block Visibility to hide draft sections of published pages.
Perhaps it should be opt-in via Block Supports? It should be possible to disable it via filters too, if it's not needed for a specific project or post type. How this plays with the Block Locking API might need consideration, too. (I'm not sure if this is handled already in Block Visibility?) If a block is locked to prevent removal, that should probably also prevent hiding. That would be useful to disable hiding within a pattern, say if it has a custom class on the pattern's group block that (for better or worse) is expecting a certain number, or specific, child blocks. |
Beta Was this translation helpful? Give feedback.
-
I interface with a lot of FSE builders and end users. Not just users who are building simple personal sites or blogs, but also builders who are several levels deeper, trying to go full-scale FSE with client sites. This is one of the biggest missing pieces for them, especially the conditional checking of posts, users, post type, etc. I recommend Block Visibility (and the Icon Block) alongside Ollie and users fall in love with the ease of use baked into this plugin, especially around checking against post/user, post type, etc. So many folks have said this would be a godsend for FSE adoption. As @bacoords put it, these template conditional are historically what make WP theming so powerful. They make sense as a baseline experience if we move forward with this in core. |
Beta Was this translation helpful? Give feedback.
-
I was thinking about this proposal a bit more and I came to the realization that these two use-cases are actually different features: 1- Hide block entirely The first one can be used for privacy reasons, things not ready... So the block should never be visible in the frontend. So the processing should be done in the server. The latter is a "style", the block should appear as you resize your screen or move your phone. So the block is actually always there and it's just CSS. You shouldn't have to reload the page to see the block. Technically for me this means that the former makes more sense in |
Beta Was this translation helpful? Give feedback.
-
I wonder what, if any overlap, this work could have with also laying the foundation for Block States. Visibility, like focus, like hover, like a number of other conditions is really just "state" #57719 ? |
Beta Was this translation helpful? Give feedback.
-
This discussion explores adding functionality to Gutenberg that allows users to hide block content in different contexts. This idea stems from my Block Visibility plugin. While the plugin offers extensive features that go beyond what should be included in Core, there are specific elements I believe would be valuable additions, including:
Starting with these two settings and making the underlying architecture extensible would provide valuable functionality to Core while also allowing extenders with an official way of adding their own visibility controls.
In my opinion, the first implementation of hiding blocks should be a boolean control similar to Figma and other design applications that allows you to simply show or hide any block. Ideally, visibility could be controlled in the List View, in the block options menu, and with a keyboard shortcut. @richtabor has an open issue for this in #50756.
Mechanically, I imagine visibility settings being an object assigned to a singular block attribute (similar to
metadata
, or could be part ofmetadata
). If we used themetadata
attribute, which is already being used for block bindings, I imagine the structure might look something like this:There are plenty of open questions about how this type of functionality should be implemented. Here are a few:
So what do you think? Feedback is welcomed.
Beta Was this translation helpful? Give feedback.
All reactions