CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Group block: Simplify variations' isActive fields #63100
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
Conversation
Size Change: -53 B (0%) Total Size: 1.94 MB
βΉοΈ View Unchanged
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
@ockham, do you mind rebasing this on top of the latest trunk? |
086d822
to
ecedae0
Compare
Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ockham! Everything works as before β
I'm seeing a minor issue but I'm not 100% sure if I'm using the feature correctly. This is my variation registration code in my custom block: // `index.js` of my custom block
import { registerBlockVariation } from "@wordpress/blocks";
import { __ } from "@wordpress/i18n";
import domReady from "@wordpress/dom-ready";
domReady(() => {
registerBlockVariation("core/group", {
name: "wpcomsp/marquee-content",
title: "Marquee Content",
icon: "editor-table",
description: __("A marquee content block."),
scope: ["block", "inserter"],
attributes: {
isMarquee: true,
layout: { type: "flex", flexWrap: "nowrap" },
className: "wpcomsp-marquee-content",
allowedBlocks: [
"core/paragraph",
"core/heading",
"core/image",
"core/buttons",
],
},
isActive: ["layout.type", "isMarquee"],
});
}); I can see the Curiously, when I increase the specificity by adding an additional item in the isActive: ["layout.type", "layout.flexWrap", "isMarquee"], But, trying to insert a Row block ends up inserting a Marquee Content instead. |
Oh, that's very weird, and somewhat concerning -- the block variation inserted being different from the one selected in the inserter seems like there's a very weird disconnect happening. I'm curious, what happens if you try using your code with GB |
I did more testing and noticed that normal Group variation ( |
Ah, good spot! I opted against setting I'm thinking to implement the latter behavior (potentially in a separate PR). |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I have to take back my approval as this feedback was meant for your other PR! the good news is that I'm approving your other PR π .
ecedae0
to
90682ac
Compare
blockAttributes.layout?.type === 'flex' && | ||
( ! blockAttributes.layout?.orientation || | ||
blockAttributes.layout?.orientation === 'horizontal' ), | ||
isActive: [ 'layout.type' ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this conflict with the Grid variation, since now that we have "same" active condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't, since the active variation detection logic will compare the value of this attribute (as specified by the variation's attributes
definition). For the Row variation, layout.type
is flex
(see two lines above); for the Grid variation, it's grid
.
(For the Column variation, where layout.type
is flex
, i.e. the same as for the Row, we supply an additional criterion -- layout.orientation
, which needs to be vertical
-- to increase specificity and thus avoid collisions.)
Flaky tests detected in 90682ac. π Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/17733383507
|
@Mamaduka Think this is good to land? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ockham!
I just re-tested the Group variations and everything works as before β
What?
Simplify active variation detection for the Group block.
Why?
To simplify code and showcase recent enhancements to active block variation detection.
It might also help with fixing #41303.
How?
By leveraging changes to active variation detection from #62088 and #62031, which allow dot notation for nested attributes (e.g.
layout.type
), and picks the variation with the highest specificity if multiple variations match the givenisActive
criteria.Testing Instructions
Insert multiple Group blocks, choosing a different variation each time. Save your post and reload the editor. Verify that the block inspector reflects the correct variation for each block.