-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 set default Group block variation in WordPress 6.3 #53750
Comments
I'm running into something similar with the cover block now. Wanting to set that to also default to not have the layout toggle on, I seem to have to unregister the default block variation (which I didn't even think existed?) for this to take effect: /* Adjust default Cover block */
wp.blocks.unregisterBlockVariation( 'core/cover', 'cover' );
wp.blocks.registerBlockVariation(
'core/cover',
{
name: 'cover',
isDefault: true,
attributes: {
layout: {
type: 'default',
},
},
}
); I'm still able to set a default Media & Text block without unregistering a block variation ahead of time (and also without a |
I was surprised as well, but it actually does have a default block variation. See here. This was added in 6.2 explicitly due to the layout controls. There is an explanation here. I need to keep investigating this, but my guess right now is that if a block already has a variation set to |
@mrwweb is the intention of this to have all Groups added with content width by default? Or without it? The Group variation was made default when it was decided that all newly added Groups should have content width. That change was made in #42763, which went into core in WP 6.1. The Cover block change that added layout has only been in core since 6.3. |
Ah thanks for the correction. I saw that PR on the 6.2 project board and didn't investigate further. After a bit more experimentation with Two variations with
|
Described behavior makes sense to me. When there's already a registered default, you'll have to unregister it first to override it with yours. |
@ndiego Thanks for such thorough research! Everything you did aligns with what I saw as well. I think you're right that updating the documentation would help a lot. I think a lot of my confusion came from the
I think I took that to mean that the "last" variation registered would "win" (as is often the case in other contexts) and replace the first one. It sounds like that isn't the intended behavior, but I do wonder if it would be a good behavior (i.e., if
Update: I was completely turned around by this setting. Sorry. It turns out I actually do want the default behavior and I think I got confused by it becoming the default behavior. (Yay!). |
Yes, that all sounds correct to me. Thanks for digging in to articulate the current behaviour! |
I'm going to go ahead and close this as it seems there isn't anything actionable here. Feel free to reopen if needed! |
Description
Split off #53517 at @ndiego's suggestion.
Update: I was very confused about the "Inherit layout" setting when writing this post, but the behaviors documented are all accurate. The primary issues are: 1) setting a default variation and 2) variation selectors overriding variation attributes.
In WordPress 6.2 (and prior versions), I could use this code to override the default Group block variation so it "inherits" the content layout (very confusing option, btw):
The first problem is that the
layout
attribute was changed. Now, instead ofinherit: true
, it needs to betype: 'default'
.However, there is a second bigger problem. That code results in a duplicate Group block in the inserter.
Adding
name: 'group'
to the code gets rid of the duplicate Group block in the inserter but then the attribute changes are ignored. (So my variation is essentially ignored.)This doesn't work:
I can get the variation to work by unregistering the default
group
variation first:However, that's still not the end of the problems! Even though that inserts a Group block with the "inherit" option toggle off, when the default Group layout (so not row or column) is selected, the Toggle is automatically set back on. My solution was to bypass the Group block variation selector by passing an empty style object to the variation as well:
So I think there are a few questions to answer:
name
? Since it worked, I assumed it was intention becauseisDefault
implies it should override the default variation (though that may be a bad assumption).Finally a few notes:
wp
global. I got the same results both times.enqueue
argument, theenqueue_block_assets
vs.enqueue_block_editor_assets
hooks, using DOMContentLoaded/wp.domReady/nothing.Step-by-step reproduction instructions
See snippets in description.
Screenshots, screen recording, code snippet
No response
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
No
The text was updated successfully, but these errors were encountered: