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

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

Closed
3 of 6 tasks
silaskoehler opened this issue Nov 28, 2024 · 3 comments
Closed
3 of 6 tasks

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

silaskoehler opened this issue Nov 28, 2024 · 3 comments
Labels
[Block] Group Affects the Group Block (and row, stack and grid variants) [Feature] Block API API that allows to express the block paradigm. [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed [Type] Bug An existing feature does not function as intended

Comments

@silaskoehler
Copy link

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
@silaskoehler silaskoehler added the [Type] Bug An existing feature does not function as intended label Nov 28, 2024
@talldan
Copy link
Contributor

talldan commented Nov 28, 2024

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

I think your hunch is right given the variation works, but it doesn't show as active.

It sounds like the same issue as #41303, which was partially fixed I think, but I don't know much about it. It might be worth reading through the issue and the related PR - #62031.

Let me know if it's the same and I can close this issue as a duplicate.

@silaskoehler
Copy link
Author

Thank you for your quick response, and apologies for not finding the other one. #41303 is exactly my issue. Perhaps we could add the "variations" label to the other one. Please feel free to close this one as a duplicate.

@t-hamano
Copy link
Contributor

Thanks for the report. Let's close this issue and continue the discussion in #41303.

@t-hamano t-hamano closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2024
@t-hamano t-hamano added [Feature] Block API API that allows to express the block paradigm. [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed [Block] Group Affects the Group Block (and row, stack and grid variants) labels Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Group Affects the Group Block (and row, stack and grid variants) [Feature] Block API API that allows to express the block paradigm. [Status] Duplicate Used to indicate that a current issue matches an existing one and can be closed [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

3 participants