-
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
Add content width to Group block by default #42582
Conversation
Size Change: +116 B (0%) Total Size: 1.26 MB
ℹ️ View Unchanged
|
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.
This is testing pretty well manually for me @tellthemachines!
It looks like my existing Group blocks are preserved with their expected default setting (inherit
set to false
), and newly created Group blocks appear to be using inherit
set to true
👍
Also, grouping blocks feels quite natural in the inherit
mode, from a UX perspective it feels like it's working quite nicely.
For testing I used the following markup from trunk:
Test group block markup
<!-- wp:group -->
<div class="wp-block-group"><!-- wp:paragraph -->
<p>A paragraph</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->
<!-- wp:group {"backgroundColor":"vivid-red"} -->
<div class="wp-block-group has-vivid-red-background-color has-background"><!-- wp:paragraph -->
<p>A paragraph within an inherit: false default group block.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->
<!-- wp:group {"backgroundColor":"luminous-vivid-orange","layout":{"contentSize":"300px"}} -->
<div class="wp-block-group has-luminous-vivid-orange-background-color has-background"><!-- wp:paragraph -->
<p>A paragraph within an inherit: false default group block with custom sizing.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->
<!-- wp:group {"backgroundColor":"light-green-cyan","layout":{"inherit":true}} -->
<div class="wp-block-group has-light-green-cyan-background-color has-background"><!-- wp:paragraph -->
<p>A paragraph within an inherit: true default group block.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->
<!-- wp:paragraph -->
<p>A regular paragraph.</p>
<!-- /wp:paragraph -->
I've added a couple of questions out of curiosity — apologies if they're obvious questions! I struggled a little bit to follow how the logic's working — it appears to be working nicely for me in practice, but I wasn't too sure why we needed the deprecation or the useEffect
to get it working, but I'm sure there's a good reason 😀
Happy to do further testing, too!
useEffect( () => { | ||
if ( inherit ) { | ||
__unstableMarkNextChangeAsNotPersistent(); | ||
setAttributes( { layout: { inherit } } ); |
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.
Why is this line required? It looks like inherit
is retrieved from layout.attributes
already, so I wasn't sure what the setAttributes
call winds up doing here 🤔
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.
I'm probably doing something wrong elsewhere, but { layout: { inherit } }
doesn't actually get saved to the block attributes without this bit of code. So without it, if you add a Group and then go into code view you can see the layout attribute isn't there. I feel there must be something I'm missing, not sure what 😅
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.
Ah, gotcha! I wonder if it's to do with the behaviour where a default value isn't serialized, but if we switch a value off and on so that setAttributes
is explicitly called, then it is serialized 🤔
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.
That might be it! I'll dig around for any precedent with adding default attributes to blocks and see if there's a better way.
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.
Looking through block-library
, I can't find another instance of an attribute having to be set on a block by default, without being tied to a specific action (e.g. in File and Image, new attributes have been added, but they are only set during upload). Not sure we'll be able to do without explicitly setting the attribute.
This is awkward, especially if new blocks want to have content width set by default 🤔
I'll continue looking into it.
@@ -38,6 +39,79 @@ const migrateAttributes = ( attributes ) => { | |||
}; | |||
|
|||
const deprecated = [ | |||
// Version with no default content width. |
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.
Why do we need the deprecation? The markup of the two different versions should be identical, so I wasn't sure if it needs a migration, since we don't want to make changes to existing blocks 🤔
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.
Again (and this might be connected to what I'm missing above?) if I don't add the migration, existing blocks with no layout set suddenly acquire a content width 😬
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.
Ah, excellent, thanks for confirming — at least knowing that much gives us a good base of behaviour for exploring our options 👍
Closing as this was superseded by #42763. |
What?
Changing the Group block so new blocks always have a content width set by default
Why?
How?
Testing Instructions
Screenshots or screencast