CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - 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:
|
Ok, let's stabilize the feature with this PR. I made the following changes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, and it's working nicely. I left a couple of small comments, but the code is really tidy. E2E tests would be nice, but can be a separate PR.
One thing I notice when testing is that some transforms might not retain the block visibility, others do. Paragraph to Preformatted seems to make the block visible again, but Preformatted to Paragraph keeps the block hidden. Not sure why, but seems like a real edge case, so again not urgent, but maybe something to fix at some point.
packages/block-editor/src/components/block-visibility/toolbar.js
Outdated
Show resolved
Hide resolved
"html": false, | ||
"inserter": false, | ||
"renaming": false, | ||
"blockVisibility": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious about the reasoning for not allowing synced patterns to be hidden. I think that might be quite a handy use case (same for template parts which are essentially another form of pattern).
It's something that can be revised later quite easily so doesn't necessarily need to be addressed in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no clear reason for this at the moment 😅 I've disabled this support for generic blocks just to be safe, but I'll consider addressing it in a follow-up.
This is the current state: I have to admit, I preferred the 0 height one quite a bit. Could we have made that also 0 width to address Dan's good note? Not suggesting this as a blocker. I think the PR should land. But I'd like, if possible, to not entirely close the door on the collapsing, because for the moment, it's still collapsing when you deselect the block, so it's arguably more confusing now than when at least the block appeared to be removed from the flow (which is the case on the frontend). |
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 <mukeshpanchal27@users.noreply.github.com>
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. |
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.
blockVisibility
block support except for some generic blocks, which defaults totrue
. When a block is hidden, its state is saved inattributes.metadata.blockVisibility
.isBlockHidden
private selector to the@wordpress/block-editor
package.blockVisibility
attribute 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.