You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
allowedBlocks does not prevent any block from being inserted via the “Enter” key or sibling inserter #6569
The allowedBlocks attribute of <InnerBlocks /> is intended to only allow certain blocks to be inserted into a block. However, by pressing Enteror by using the sibling inserter(fixed by #7226), you can still insert the default block: the Paragraph block.
Steps to Reproduce (for bugs)
Create a block type containing <div><InnerBlocks allowedBlocks={ [ 'core/list' ] } /></div> in its editor markup and <div><InnerBlocks.Content /></div> in its saved markup. This block should allow only allow List blocks to be inserted into it as children.
Insert the block into a post.
Insert multiple List blocks into the container block.
Try using the sibling inserter orEnter to insert a Paragraph block.
Notice that, although the Paragraph block is not shown in the inserter pop-up, it can still be inserted.
Expected Behavior
A block that sets allowedBlocks in its <InnerBlocks /> component should only allow the blocks listed in allowedBlocks to be inserted into it. Of course, the question of how to still use slash commands and/or the sibling inserter arise, as both involve inserting Paragraph blocks.
Current Behavior
Using Enteror the in-between inserter, you can insert any block into a block with an <InnerBlocks /> component.
The PR #6067 made the slash command respect allowed blocks.
But we still can not close this issue because if allowedBlocks does not accept core/paragraph it can still be inserted via the in-between inserter.
@jorgefilipecosta Yeah, I created #6834, which suggests removing the placeholders from <InnerBlocks/> and having the inserter pop-up be accessible directly from the sibling inserter.
Furthermore, I believe if you have <InnerBlocks allowedBlocks={ [ 'core/list' ] } /> it still allows to insert a paragraph block. In some cases paragraph would not be good, specially as default.
Might be unrelated, but is there a way to create a block that can not be inserted anywhere, but only when specifically mentioned in allowedBlocks?
The use case for example would be to make a custom/list block that can only accept custom/listitem blocks. A custom/listitem block inserted outside of the list context would not be formatted correctly.
In this case the custom/list would contain <InnerBlocks allowedBlocks={ [ 'custom/listitem' ] } /> and currently when adding a new item it would still create a paragraph by default, but it should instantly make the list item.
@chrisvanpatten thanks, parent: [ 'custom/list' ], indeed makes it unavailable to be inserted in any other context.
Only problem that remains is that when adding a new item it opens a block selector even though only 1 possible option is available and it could just insert that block straight away
And if you click the area on the left of the + icon it will create a paragraph.
#7226 has partially fixed another part of this. The default placeholder block no longer appears in nested contexts where the default block (the Paragraph block) is not allowed, and neither does the sibling inserter. Personally, I think the sibling inserter should just open up in the insertion pop-up directly. See #6834 and #7763.
But anyway, that leaves one way left of inserting the wrong block that is described in this issue: pressing Enter. If you have a block that only allows something like Heading or List blocks and you press Enter in them, you can create Paragraph blocks even though that should not be allowed.
There is also the issue of being able to move blocks into a context where they are not allowed (which was not mentioned by this issue), but that should be fixed by #7212.
Another issue is that you can transform a block that is allowed in the parent block to another block that is not allowed in the parent block. This is covered by #6363 and should be fixed by #7184.
changed the title [-]allowedBlocks does not prevent any block from being inserted via the in-between inserter and slash commands[/-][+]allowedBlocks does not prevent any block from being inserted via the “Enter” key and sibling inserter[/+]on Jul 13, 2018
changed the title [-]allowedBlocks does not prevent any block from being inserted via the “Enter” key and sibling inserter[/-][+]allowedBlocks does not prevent any block from being inserted via the “Enter” key or sibling inserter[/+]on Jul 13, 2018
Activity
jorgefilipecosta commentedon Jun 8, 2018
The PR #6067 made the slash command respect allowed blocks.
But we still can not close this issue because if allowedBlocks does not accept core/paragraph it can still be inserted via the in-between inserter.
ZebulanStanphill commentedon Jun 8, 2018
@jorgefilipecosta Yeah, I created #6834, which suggests removing the placeholders from
<InnerBlocks/>and having the inserter pop-up be accessible directly from the sibling inserter.ktmn commentedon Jul 5, 2018
Furthermore, I believe if you have
<InnerBlocks allowedBlocks={ [ 'core/list' ] } />it still allows to insert a paragraph block. In some cases paragraph would not be good, specially as default.Might be unrelated, but is there a way to create a block that can not be inserted anywhere, but only when specifically mentioned in
allowedBlocks?The use case for example would be to make a
custom/listblock that can only acceptcustom/listitemblocks. Acustom/listitemblock inserted outside of the list context would not be formatted correctly.In this case the
custom/listwould contain<InnerBlocks allowedBlocks={ [ 'custom/listitem' ] } />and currently when adding a new item it would still create a paragraph by default, but it should instantly make the list item.chrisvanpatten commentedon Jul 5, 2018
@ktmn I think the "parent" attribute is what you need. See here in the core column block:
https://github.com/WordPress/gutenberg/blob/master/core-blocks/columns/column.js#L18
ktmn commentedon Jul 6, 2018
@chrisvanpatten thanks,
parent: [ 'custom/list' ],indeed makes it unavailable to be inserted in any other context.Only problem that remains is that when adding a new item it opens a block selector even though only 1 possible option is available and it could just insert that block straight away
And if you click the area on the left of the
+icon it will create a paragraph.Should I make a separate issue of this?
Sibling Inserter: Hide insertion point if it is not possible to inser…
ZebulanStanphill commentedon Jul 13, 2018
#7226 has partially fixed another part of this. The default placeholder block no longer appears in nested contexts where the default block (the Paragraph block) is not allowed, and neither does the sibling inserter. Personally, I think the sibling inserter should just open up in the insertion pop-up directly. See #6834 and #7763.
But anyway, that leaves one way left of inserting the wrong block that is described in this issue: pressing Enter. If you have a block that only allows something like Heading or List blocks and you press Enter in them, you can create Paragraph blocks even though that should not be allowed.
There is also the issue of being able to move blocks into a context where they are not allowed (which was not mentioned by this issue), but that should be fixed by #7212.
Another issue is that you can transform a block that is allowed in the parent block to another block that is not allowed in the parent block. This is covered by #6363 and should be fixed by #7184.
[-]allowedBlocks does not prevent any block from being inserted via the in-between inserter and slash commands[/-][+]allowedBlocks does not prevent any block from being inserted via the “Enter” key and sibling inserter[/+][-]allowedBlocks does not prevent any block from being inserted via the “Enter” key and sibling inserter[/-][+]allowedBlocks does not prevent any block from being inserted via the “Enter” key or sibling inserter[/+]designsimply commentedon Aug 21, 2018
Closing in order to consolidate to #8589 which is a task that should help resolve this issue and other similar cases.