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

Update InnerBlocks defaultblock doc usage #56728

Conversation

colorful-tones
Copy link
Member

@colorful-tones colorful-tones commented Dec 1, 2023

What?

Recently the defaultBlock was stabilized as part of WP 6.4 (#52083). However, the InnerBlocks README docs were incomplete. I received additional clarification from @sethrubenstein (see here: #52610 (comment))

Why?

Clear instructions for extenders on how to use defaultBlock

How?

Adds clarity to documentation.

I verified while creating a custom block with useInnerBlocksProps(). Here is the essential code that worked.

const innerBlocksProps = useInnerBlocksProps(
    defaultBlock: {
        name: 'core/cover',
        attributes: {
            dimRatio: 0,
	    layout: {
		type: 'constrained',
	    },
        },
    },
    directInsert: true,
);

props: @sethrubenstein

@colorful-tones colorful-tones self-assigned this Dec 1, 2023
@colorful-tones colorful-tones added [Type] Developer Documentation Documentation for developers [Feature] Nested / Inner Blocks Anything related to the experience of nested/inner blocks inside a larger container, like Group or P labels Dec 1, 2023
- **Default:** - `undefined`. Determines which block type should be inserted by default and any attributes that should be set by default when the block is inserted. Takes an array in the form of `[ name: blockname, attributes: {blockAttributes} ]`.

```jsx
const DEFAULT_BLOCK = [ name: 'core/paragraph', attributes: { content: 'Lorem ipsum...' } ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems wrong to me, it's either an array or an object, not a mix of both (this notation doesn't work in JavaScript)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@youknowriad thanks for catching that! I've updated the accepted type to Object.

Co-authored-by: Riad Benguella <benguella@gmail.com>
@youknowriad youknowriad merged commit 0fa652a into WordPress:trunk Dec 7, 2023
49 checks passed
@youknowriad
Copy link
Contributor

Thanks for clarifying these docs 👍

@github-actions github-actions bot added this to the Gutenberg 17.3 milestone Dec 7, 2023
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] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants