Can't create a card Block Variation for the Group Block
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.https://github.com/WordPress/gutenberg/blob/b54d1fe5fe96b00d7f6455b4aaf40bb21ec43967/packages/block-library/src/group/variations.js#L62-L73
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
- register a block variation with registerBlockVariation and try to override the default group block variation.
Screenshots, screen recording, code snippet
Environment info
- WordPress Studio
- WordPress 6.7 with default theme
- Chrome Browser
Please confirm that you have searched existing issues in the repo.
- [x] Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
- [x] Yes
Please confirm which theme type you used for testing.
- [x] Block
- [ ] Classic
- [ ] Hybrid (e.g. classic with theme.json)
- [ ] Not sure
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 https://github.com/WordPress/gutenberg/issues/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 - https://github.com/WordPress/gutenberg/pull/62031.
Let me know if it's the same and I can close this issue as a duplicate.
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.
Thanks for the report. Let's close this issue and continue the discussion in #41303.