-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add ability to limit the number of items within an Inner Blocks area #42342
Comments
Reusing A flexible approach would be to provide individual control over whether blocks can be added, moved or removed. As @fabiankaegy mentioned, it probably requires a new prop. One way to achieve that would be an
Sebastian |
Would love to see this get added! Have tons of use-cases for this... Here's a few in support:
Not sure what the solution would be, but like the idea of expanding on the "templateLock" prop as a start. |
We'd really appreciate this too. Max inner blocks would be really helpful |
This is much needed for us as well. A use case: If anyone has any ideas ideas in the mean time, that would be much appreciated. |
+1. I would appreciate both the ability to set a For example, I recently created a custom block that allows you to feature posts from another custom post type but the design directive explicitly asked us to not allow more than 6, but less than 6 was okay. If the templateLock featured had a In cases where this is part of a larger template, it would also be super helpful to be able to set a In plugins like ACF, the Repeater block lets you do this very easily and it makes sense to have these two properties as part of the |
Followed a tutorial https://ryanwelcher.com/2020/10/limiting-the-block-count-for-innerblocks/ for this but still had problems limiting the inserter on core blocks with parent/child relations as stated by fabiankaegy. I think proposed solutions can really help with getting more control over the innerBlocks. |
+1. |
I also followed the approach noted in https://ryanwelcher.com/2020/10/09/limiting-the-block-count-for-innerblocks/. I set up the code within
This worked for the default appender, but the in-between appender still displays when hovering between innerblocks. You can also add more innerblocks using the block inserter. Given there isn't a great way to fully limit the number of innerblocks added, we'd love a more standardized approach. |
This 🎅🏻 |
What problem does this address?
Part of #41236.
When you have a custom tabs block for example you can build that to work similar to the core columns block. You have one wrapping block that contains individual tab item or column blocks that intern allow editors to place other blocks inside of them. The issue however is that you may want to restrict the ability of editors to add more than 5 tabs which currently isn't possible.
Tabs are just an example here. This applies to all kinds of blocks that follow the parent/child block relationship. Even the Core Columns block doesn't really support more than 6 columns. But editors can still select an individual column block and duplicate it.
As a workaround, you can define a custom
renderAppender
function for the area of the inner block and only render the custom block appended whenever there are fewer than the max number of items in the area of the inner block. But that still doesn't solve the root issue because editors can still duplicate a block to create more than should be possible.What is your proposed solution?
Add a new optional prop to the
InnerBlocks
props that allows developers to set a max number of items. It could also be achieved by introducing a new level oftemplateLock
which would prevent adding more items whilst still not locking down any of the already existing items.The text was updated successfully, but these errors were encountered: