• I have custom block with spacing.blockGap : true in block.json (I just copied it from group block)

    "supports": {
    	"spacing": {
    		"margin": true,
    		"padding": true,
    		"blockGap": true,
    		"__experimentalDefaultControls": {
    			"padding": true,
    			"blockGap": true
    		}
    	}
    },

    This block is just a wrapper with some css grid styles.

    // save.js
    export default function save(props) {
    	const innerBlocksProps = useInnerBlocksProps.save(useBlockProps.save());
    	
    	return (<div {...innerBlocksProps}></div>)
    }
    
    // edit.js
    export default function Edit() {
    	const innerBlocksProps = useInnerBlocksProps(
    		useBlockProps(),
    		{
    			allowedBlocks: ['my-theme/inner-block'],
    		});
    
    	return (<div {...innerBlocksProps}></div>)
    }

    How do I implement gap support?

    The editor displays control for editing.

    And When I save I get correct value in attributes:

    <!-- wp:my-theme/outer-block {"style":{"spacing":{"blockGap":"var:preset|spacing|60"}}} -->
    <div class="wp-block-my-theme-outer-block">
        <!-- wp:my-theme/inner-block --> ... <!-- /wp:my-theme/inner-block -->
    </div>
    <!-- /wp:my-theme/outer-block-->

    But in front-end gap doesn’t applyed to this block.

    At the same time if I create build-in group block and set blockGap in front end WP adds new class wp-container-6 with gap styles.

    What should I do to tell WP add gap-classes to my block?

Viewing 3 replies - 1 through 3 (of 3 total)
  • These classes will only be added to the frontend if __experimentalLayout support is set. As there are still changes being made in the layout API it is not recommended that custom blocks implement this as there could be changes in future Gutenberg plugin releases that cause breakages to the layout.

    The plan is to stabalize this support in 6.3, so the recommendation is for custom blocks to wait until them before implementing and use your own custom controls in the mean time.

    Sounds good @glendaviesnz . I’m guessing the best course of action would just be to warp the inner content of the custom block in a group and then utilize that for block spacing?

    @badg0003 if that works for your use case it would be the safest approach until __experimentalLayout is stabilised.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to implement spacing.blockGap support in custom block?’ is closed to new replies.