Skip to content

Can't create a card Block Variation for the Group Block #67374

@silaskoehler

Description

@silaskoehler

Description

I try to register a BlockVariation like so:

registerBlockVariation( 'core/group', {
	name: 'card',
	title: 'Karte',
	description: 'Style Group as a Card',
	attributes: {
		anchor: 'is-card',
	},
	isActive: [ 'anchor' ],
} );

I can insert the variation in the editor, but it is not active after I insert it.

My guess was that there might be a conflict with the default group:variation.

name: 'group',
title: __( 'Group' ),
description: __( 'Gather blocks in a container.' ),
attributes: { layout: { type: 'constrained' } },
isDefault: true,
scope: [ 'block', 'inserter', 'transform' ],
isActive: ( blockAttributes ) =>
! blockAttributes.layout ||
! blockAttributes.layout?.type ||
blockAttributes.layout?.type === 'default' ||
blockAttributes.layout?.type === 'constrained',
icon: group,

So i try to give a stronger isActive specification, but it does not work for me.

registerBlockVariation( 'core/group', {
	name: 'card',
	title: 'Card' ,
	description:  'Style Group as a Card',
	attributes: { layout: { type: 'constrained', className: 'is-card' } },
	isActive: ( blockAttributes ) =>
		blockAttributes.className === 'is-card' &&
		( ! blockAttributes.layout ||
			! blockAttributes.layout?.type ||
			blockAttributes.layout?.type === 'default' ||
			blockAttributes.layout?.type === 'constrained' ),
} );

Do i miss something?

Step-by-step reproduction instructions

  1. register a block variation with registerBlockVariation and try to override the default group block variation.

Screenshots, screen recording, code snippet

Image

Environment info

  • WordPress Studio
  • WordPress 6.7 with default theme
  • Chrome Browser

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Block] GroupAffects the Group Block (and row, stack and grid variants)[Feature] Block APIAPI that allows to express the block paradigm.[Status] DuplicateUsed to indicate that a current issue matches an existing one and can be closed[Type] BugAn existing feature does not function as intended

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions