Skip to content

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

Closed

Description

@ZebulanStanphill

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.

Activity

  1. added
    [Type] BugAn existing feature does not function as intended
    [Feature] InserterThe main way to insert blocks using the + button in the editing interface
    on Jun 4, 2018
  2. jorgefilipecosta commented on Jun 8, 2018

    @jorgefilipecosta
    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.

  3. ZebulanStanphill commented on Jun 8, 2018

    @ZebulanStanphill
    MemberAuthor

    @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.

  4. ktmn commented on Jul 5, 2018

    @ktmn

    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.

  5. chrisvanpatten commented on Jul 5, 2018

    @chrisvanpatten
    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

  6. ktmn commented on Jul 6, 2018

    @ktmn

    @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?

  7. ZebulanStanphill commented on Jul 13, 2018

    @ZebulanStanphill
    MemberAuthor

    #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.

  8. 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
  9. 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
  10. designsimply commented on Aug 21, 2018

    @designsimply
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] InserterThe main way to insert blocks using the + button in the editing interface[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions