Introduce block support and UI for allowedBlocks#71986
Conversation
|
Size Change: +895 B (+0.05%) Total Size: 1.96 MB
ℹ️ View Unchanged
|
62f3846 to
a9e46bb
Compare
|
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. |
|
Flaky tests detected in c4447a3. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/18331165365
|
That's only a problem if users are allowing most blocks, rather than allowing just a few (which from the issue seems to be the most likely scenario). So it's probably fine 😄 |
|
This is very cool. I could see this being really useful for patterns, possibly connected to the recent idea mentioned in #71887 about being able to specify a 'Free area' where only content blocks can be inserted. There are a few of small bits of UI food for thought that I noticed (might be worth getting design feedback):
It'd be great to get a designer's feedback on those things. |
tellthemachines
left a comment
There was a problem hiding this comment.
This is looking good and testing well for me!
Given that most other generic container blocks have an allowedBlocks attribute similar to Group, should we update them all to use the block support instead? (I think all containers that allow all block types have it except for Quote, which I think should have it too 😄 - but adding it to new blocks is maybe best in another PR)
One thing I noticed in testing is that, if focus is in an empty block inside the container with allowedBlocks set and we try to add a non-allowed block from the inserter, it doesn't get added at all. I'd expect it to be added outside the allowedBlocks container:
allowed-blocks.mp4
This is an existing bug in trunk though, not caused by this changeset.
Another thing that occurred to me in testing is that it would be really nice to be able to deselect all blocks with one click, especially for those cases where we only want to allow one or two blocks. Again, not a change for this PR, but something to consider.
packages/block-editor/src/components/block-allowed-blocks/allowed-blocks-control.js
Outdated
Show resolved
Hide resolved
|
Thanks for the feedback!
Yes. In this PR, I've added support only to the Group block to let you try out the actual UI. If this UI works well, I plan to add this support to all relevant core blocks in a follow-up.
That's right. The initial proposed design recommended the Advanced panel, but as mentioned in this comment, the UI order may be swapped. Do we try to reserve a special slot here for the allowedBlocks UI?
I agree, maybe we need to extend the BlockManager component itself. I welcome design feedback! |
|
Update: I created a private slot fill and moved the toggle button there so that it would always be rendered last in the Advanced panel. I also removed the
|
|
Designwise, looks good at a glance, especially after you added the help text. The partially duplicated title ("Allowed blocks" in the modal, "Manage allowed blocks" inside) is the only slightly uncanny thing. I realize that is based on the original design, the main difference being that the modal shown there has a gray border under its header, which made a bit of a difference. We shouldn't add that border back, and arguably what you have here is solid (so ship it). If we did want to try an alternative, it could be to have the modal be called "Manage allowed blocks", and have a single paragraph of text (not help text) at the top of the content. But that would create its own disconnect with the "Allowed blocks" button title. In any case, looks good! |
|
@jasmussen Thanks for the review! How about this?
|
|
Looks good, and that's what I pictured. But what you had also works. I think it probably boils down to the button that says "Allowed blocks", which is short, concise and a good label to translate without wrapping. If it's okay to keep that button title, but the modal saying something different, then I think it can work. If the modal title should be the same, I'd keep what you had before. Any preference? Thanks as always. |
|
I see what you mean, a subheading saying "Allowed blocks", which then beckons a different label below, such as "Manage", or "Manage allowed blocks". Note if we do the latter, I'd make it sentence case, "blocks". On a separate note, it'd be nice to ensure we have |
|
I don't mind the longer title, this is a context in which we can be verbose. The only risk is that translations become so long the text inside might wrap. Might be good to do a spot test of some of the more common long translations, such as German: "Zulässige Blöcke verwalten". If that can fit, we're probably good? |
tellthemachines
left a comment
There was a problem hiding this comment.
Thanks for iterating! Just a small labelling issue I noticed below, and a question: I thought from the conversation we were matching the button text to the modal title? This is what I'm seeing on this branch:
It seems redundant to have both "Allowed blocks" and "Manage allowed blocks" as headings in the modal, both visually and semantically, because the h1 and h2 are both functioning as headings for the same component.
packages/block-editor/src/components/block-allowed-blocks/allowed-blocks-control.js
Outdated
Show resolved
Hide resolved
Sorry, I forgot to push this change about modals. Fixed by 2e1e7b4. |
tellthemachines
left a comment
There was a problem hiding this comment.
Thanks, LGTM now!
|
Thanks for the review, everyone! What do you think about extending this support to other core blocks? If it's required for the 6.9 release, I'd be happy to address it |
I think it makes sense to extend it, at a minimum, to other generic container blocks that already have the I'd also love to see it in the Quote block because it's the same kind of generic container (the fact that it doesn't have the attribute currently seems like an oversight). |
* Introduces block support and UI for allowedBlocks * Move "Disabled blocks count" section outside BlockManager component * Create private slotfill and move trigger button inside Adbvanced Panel * Add subtitle and description text * Add "Select all" checkbox * Update Block Supports doc * Update description * Add basic e2e tests * Change button text * Update modal title and description text * Use BaseControl.VisualLabel instead of label prop Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: tellthemachines <isabel_brison@git.wordpress.org> Co-authored-by: talldan <talldanwp@git.wordpress.org> Co-authored-by: jasmussen <joen@git.wordpress.org> Co-authored-by: seifeldinio <seifradwane@git.wordpress.org> Co-authored-by: jhmonroe <jhmonroe@git.wordpress.org> Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org> Co-authored-by: gziolo <gziolo@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: ndiego <ndiego@git.wordpress.org> Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org> Co-authored-by: mtias <matveb@git.wordpress.org>





Closes #62703
What?
This PR implements two features:
allowedBlocksblock supportattributes.allowedBlocksWhy?
Some blocks support the
allowedBlocksattribute and pass it as an option touseInnerBlockPropsto control which blocks can be inserted. This is convenient, but it can be inconvenient as it requires you to open a code editor and manually update the attributes.How?
allowedBlocksblock support. In this PR, I added this new support to the Group block only.The concern with this PR is that all available blocks are stored as attributes, which can lead to code that looks like this:
Testing Instructions
Screenshots or screencast
1f2ffb2b4e2d42f3b33a0ed6ca74bcd4.mp4
ToDo