-
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 align support to the image block - alternative #55954
Add align support to the image block - alternative #55954
Conversation
Size Change: -37 B (0%) Total Size: 1.7 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.
I made one change of removing the custom align
attribute and allowing the block supports to add it.
Tested both the image block and the gallery block, and everything seems to work.
I'm not sure of the purpose of align support within the context of the gallery, but the behavior matches trunk.
"align": { | ||
"type": "string" | ||
}, |
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 went ahead and added a commit to remove this since it gets added by the block supports. The only difference should be the serialization order moving the align attribute to the block support section after the custom attribute section.
@@ -19,25 +19,25 @@ exports[`Align options for group block sets Wide width option 1`] = ` | |||
`; | |||
|
|||
exports[`Align options for media block sets Align center option 1`] = ` | |||
"<!-- wp:image {"align":"center","id":1,"sizeSlug":"large","linkDestination":"none"} --> |
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.
Technically this test was incorrect before as it was testing the image block's align implementation instead of the hook, so it's nice that it's testing the correct thing now.
@talldan since the discussion around adding a filter is complex in regard to where the filter is best suited - although your idea to add a filter for issues like #19103 is better than this PR - I suggets we land an effect to close the issue and come back to the filter when we develop a better, more holistic understanding. It's easy to remove this effect when we have a better, more universal solution. What do you think? |
👍 Sure, go for it. This is testing well for me, so no issues with merging it. |
This tests well for me. I was specifically looking for potential issues when the Lightbox is enabled but didn't find any 👍 |
…gn is wide or full
This allows the block supports to add the attribute instead keeping things cleaner.
5ee9aa7
to
e5c65b6
Compare
I think on principle I agree with this change. But there are a few things that we should be very careful about here. I think image blocks work differently between very old classic themes (no layout support, no theme.json...) and new ones, so we should make sure that there's no impact there editor and frontend. The other thing I noticed is that the "align" support is responsible for adding the classnames to both frontend and editor, this PR however doesn't remove the custom code that we have in save and edit functions of the image block that does the same. Does that mean we'll end up with duplicate classnames? Was that accounted for differently? |
Ha, I think the support overwrites the classname in the save function. I'll do a PR to remove the save code as it's not needed anymore. In my testing removing that does not have any effect. |
Alternative to #55346
Closes #19103
This PR removes the custom align control from the image block and makes the block support align controls.
Approach
This PR proposes resets the image aspect ratio, dimentions and cover attributes via an effect when the align attribute is updated to be one of
wide
orfull
.The downsides of this approach are:
__unstableMarkNextChangeAsNotPersistent
to get out of the trouble with using effects :) I think since we keep using this maybe we should have a history api that allows us to sayhistory.pause()
andhistory.resume()
.In #55346 a more complicated alternative is explored which proposes a new filter on the align support behavior which would open the possibility to change how any block that suports align wide or full does collateral attribute updates.