Skip to content
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

allowedBlocks does not prevent any block from being inserted via the “Enter” key or sibling inserter #6569

Closed
ZebulanStanphill opened this issue May 3, 2018 · 7 comments
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Bug An existing feature does not function as intended
Milestone

Comments

@ZebulanStanphill
Copy link
Member

ZebulanStanphill commented May 3, 2018

Issue Overview

The allowedBlocks attribute of <InnerBlocks /> is intended to only allow certain blocks to be inserted into a block. However, by pressing Enter or by using the sibling inserter(fixed by #7226), you can still insert the default block: the Paragraph block.

Steps to Reproduce (for bugs)

  1. 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.
  2. Insert the block into a post.
  3. Insert multiple List blocks into the container block.
  4. Try using the sibling inserter or Enter to insert a Paragraph block.
  5. 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 Enter or the in-between inserter, you can insert any block into a block with an <InnerBlocks /> component.

Related Issues and/or PRs

Update: 2018-07-13

Updated this issue to no longer cover the slash command bug, which was already covered by #6070 and was fixed by #6067.

@danielbachhuber danielbachhuber added [Type] Bug An existing feature does not function as intended [Feature] Inserter The main way to insert blocks using the + button in the editing interface labels Jun 4, 2018
@danielbachhuber danielbachhuber added this to the Merge Proposal: Editor milestone Jun 4, 2018
@jorgefilipecosta
Copy link
Member

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
Copy link
Member Author

ZebulanStanphill commented 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
Copy link

ktmn commented 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/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
Copy link
Contributor

@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
Copy link

ktmn commented 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?

jorgefilipecosta added a commit that referenced this issue Jul 10, 2018
…t the default block (#7226)

Fixes part of #6569.
Part of a general polishing to get #6993.

Insertion point was violating the allowedBlocks restriction of the parent block. The insertion point always inserts the default block and it may not be possible to insert the default block.

This PR makes sure insertion point only appears if it is possible to insert the default block.
@ZebulanStanphill
Copy link
Member Author

ZebulanStanphill commented 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.

@ZebulanStanphill ZebulanStanphill 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 Jul 13, 2018
@ZebulanStanphill ZebulanStanphill 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 Jul 13, 2018
@designsimply
Copy link
Member

Closing in order to consolidate to #8589 which is a task that should help resolve this issue and other similar cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Inserter The main way to insert blocks using the + button in the editing interface [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

6 participants