-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Group block: Simplify variations' isActive fields #63100
base: trunk
Are you sure you want to change the base?
Conversation
Size Change: -62 B (0%) Total Size: 1.76 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 😅 .
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.