-
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
Add content width to Group block by default #42582
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useSelect } from '@wordpress/data'; | ||
import { useSelect, useDispatch } from '@wordpress/data'; | ||
import { useEffect } from '@wordpress/element'; | ||
import { | ||
InnerBlocks, | ||
useBlockProps, | ||
|
@@ -67,6 +68,16 @@ function GroupEdit( { attributes, setAttributes, clientId } ) { | |
} | ||
); | ||
|
||
const { __unstableMarkNextChangeAsNotPersistent } = | ||
useDispatch( blockEditorStore ); | ||
const { inherit = false } = layout; | ||
useEffect( () => { | ||
if ( inherit ) { | ||
__unstableMarkNextChangeAsNotPersistent(); | ||
setAttributes( { layout: { inherit } } ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this line required? It looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm probably doing something wrong elsewhere, but There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Looking through This is awkward, especially if new blocks want to have content width set by default 🤔 I'll continue looking into it. |
||
} | ||
}, [ inherit ] ); | ||
|
||
return ( | ||
<> | ||
<InspectorControls __experimentalGroup="advanced"> | ||
|
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 👍