-
Couldn't load subscription status.
- Fork 4.6k
Block API: Add block visibility control support and UI #71203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Size Change: +1.84 kB (+0.09%) Total Size: 1.95 MB
ℹ️ View Unchanged
|
9715418 to
6436944
Compare
|
Flaky tests detected in ff7a8d5. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18160190902
|
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Nice work. I just shared some mockups in the main issue, which instead of dimming/overlaying the hidden block, actually hides it. In my comment I acknowledge the pros and cons to doing that, but since you already have a PR ready, I'm wondering if actually testing out the theory with something real isn't the best way to help decide. Beyond surfacing the potential need for focus handling, my hope is it'll make the behavior very obvious and intuitive in a way that opens up future opportunities. What do you think? |
|
Working well thus far :) Thanks for all your efforts here. It's interesting to try this with inner blocks/container blocks. I think we can learn a lot from block locking here in terms of UX: hiding.blocks.mov |
I'd suggest that both would actually be useful (also commented something to that effect in the issue):
Future compatibility with breakpoints or other variables can be left open if we keep the data structure flexible, though @t-hamano has already thought about this. Oh, I don't know, something like: |
Ah, I think this problem is related to this issue: This issue will likely occur with any blocks that extract only specific attributes and call createBlock within the transform property's callback function. We may need to fix this in a follow-up so that all three metadata attributes ( |
I agree. Fixed in 96428fd
I tried it, but since blocks in the editor are horizontally centered, the toolbar movement can be annoying: I'll try to find a better approach to hiding selected blocks in a follow-up. |
|
Potentially can default to height: 0, and look at |
Another issue I spotted with both |
Yes, I'm investigating this... |
Co-authored-by: Mukesh Panchal <[email protected]>
|
I understand what the ideal behavior here would be, but I haven't yet figured out how to technically achieve all of the following:
|
|
I want to briefly pause and thank you for your work. It's been inspiring, it's been great. Then I want to echo that this is solid work, I think it should land. To me it even feels 6.9 ready. Now whether we implement the visibility or the opacity change as you had earlier and land this, then explore height/width/collapsing separately, I'll defer to you all. To be very clear, I think it's an important value add, worth pursuing. But I also don't think it is required for the first iteration to land, especially as the block really does truly disappear when you deselect the block. That feels the main constraint. |
|
How about this? 0363abf6c5d54fccb6d04ea803ad3bbc.1.mp4 |
|
(⊃。•́‿•̀。)⊃━☆.*・ magic |
This comment was marked as resolved.
This comment was marked as resolved.
|
Thanks for the great work on this one @t-hamano 🫶 |
|
I am thinking that one can use this feature to add multi language features. |
|
Hide a block in the frontend is really useful and much loved by my trainees, when using Plugins like Greenshift (predefined CSS Class hide_onfrontend => display:none) or Block Visibility. But the actual Gutenberg & Beta 1 tool hides the block ALSO in the editor!
Suggestions: |
|
Block visibility manager of some sort should be in Gutenberg, yes. However, current implementation looks questionable, imo.
I'm extensively using https://github.com/ndiego/block-visibility plugin for managing block visibility state. Plugin seems to be really solid, open-source, somewhat easy to extend. It also allows not only basic show/hide but also a lot of other different options to manage the visibility (by query strings, screen sizes, user roles, etc.). I wished core Gutenberg implementation could borrow some ideas from a plugin like this :) |
|
@burnuser @enodekciw Thanks for the feedback.
There is a discussion about this here: #71203 (comment) In many design tools, hiding a layer actually makes that layer disappear. If you want to edit a layer, you need to explicitly show that layer. Also, in order to see how it will ultimately be displayed on the front end, the block needs to be hidden in the editor as well. That's my understanding, but I agree that there are certainly many steps involved in editing the content of a hidden block.
I think this needs to be carefully considered based on various user feedback. This is because it is difficult to remove a feature once it has been added. We have a responsibility to ensure full backward compatibility.
One reason is to avoid confusion with the CSS property "visibility". See #50756 (comment)
I'm also aware of that plugin. We can consider which ideas to incorporate as part of future enhancements. If you have any specific ideas about what kind of feature enhancements are needed, we would welcome you to submit a new issue. |

First implementation for #50756
What?
This PR adds a new block API and UI for toggling block visibility
in the frontendin both the frontend and the editor..Note: First of all, I would like to discuss why this feature is necessary and what kind of extensibility it can potentially offer in the future. Any feedback would be appreciated.
Why?
Sometimes users may want to edit blocks in the backend without affecting the frontend, for example, a section that is not yet ready to be published.
How?
Implementation details are as follows. Many of the specifications are similar to Block Lock.
blockVisibilityblock support except for some generic blocks, which defaults totrue. When a block is hidden, its state is saved inattributes.metadata.blockVisibility.isBlockHiddenprivate selector to the@wordpress/block-editorpackage.blockVisibilityattribute isfalse:Testing Instructions
Testing Instructions for Keyboard
In the List View, use the Tab key to focus on the hidden block. Your screen reader should announce something like this:
Screenshots or screencast
7e3b756925b3e09bc0c6050f75602f49.mp4
Tasks
Below is a list of things I can think of that need to be addressed and discussed.