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

Default block, but only within a parent/outer block #7573

Closed
nb opened this issue Jun 27, 2018 · 2 comments
Closed

Default block, but only within a parent/outer block #7573

nb opened this issue Jun 27, 2018 · 2 comments
Labels
[Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] Task Issues or PRs that have been broken down into an individual action to take

Comments

@nb
Copy link
Member

nb commented Jun 27, 2018

When I press Tab after the last element in my inner block, Gutenberg helpfully creates a new paragraph for me. Unfortunately it's not one of the allowedBlocks for the parent and I would prefer that the default block is the one I choose. Is this possible?

My research showed that I could use setDefaultBlockName() and I could possible hack it to respect the context (based on focus), but I hope there is a better way.

@nb nb added [Type] Question Questions about the design or development of the editor. [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P labels Jun 27, 2018
@mtias mtias added [Type] Task Issues or PRs that have been broken down into an individual action to take and removed [Type] Question Questions about the design or development of the editor. labels Jul 19, 2018
@goldenapples
Copy link

goldenapples commented Aug 14, 2018

Since #7732, the block inserter is no longer shown if the default block is not one of the blocks allowed in an InnerBlocks area. However, this makes the inner blocks area somewhat unusable unless it defines its own UI for adding child blocks, by modifying the template or some other method.

As an example, I have a carousel block which can accept a couple different types of blocks as inner blocks content, but not the default paragraph block. Up till now I've been using the default block appender as the mechanism for inserting new content slides (with some CSS hackery to make the block appender appear as a new slide, and to prevent inserting and any blocks but the blocks I wanted to allow...) The block appender provides a really consistent and user-friendly interface for adding content to nested blocks.

I think it would be really nice to be able to specify a default block for inner blocks areas that's different from the root default block, like this:

<InnerBlocks
    allowedBlocks={ [
        'custom/responsive-image',
        'custom/image-with-card',
    ] }
    defaultBlock={ 'custom/responsive-image' }
/>

which, along with some context-aware modifications to the logic in canInsertDefaultBlock, would allow these nested block regions to use a default block appender, and style it as needed for their own purposes.

@nerrad
Copy link
Contributor

nerrad commented Jun 3, 2019

It looks like this functionality can be added via a custom appender added to InnerBlocks. See documentation here and the related pull here: #14241

@nerrad nerrad closed this as completed Jun 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

No branches or pull requests

4 participants