-
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
Block: fix alignments #19704
Block: fix alignments #19704
Conversation
9a83a8a
to
61e310d
Compare
packages/block-editor/src/components/block-list/block-popover.js
Outdated
Show resolved
Hide resolved
Co-Authored-By: Chris Van Patten <hello@chrisvanpatten.com>
|
||
return <Component { ...props } className={ className } />; | ||
if ( attributes.align ) { | ||
return <div className="is-block-content">{ component }</div>; |
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 not add it in block.js ?
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 could add it there as well.
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.
Done :)
I don't believe how fast you fixed this. It appears to work just as it should, even for things like embeds. So just on the experience, 👍 👍! Impressive work. I noticed you fixed it using a |
I'm not sure. I think eventually we'll probably see something similar, because, while the block could provide this wrapper in the future, the toolbar will still have to be positioned at this wrapper instead of the parent element (which spreads the whole length). I could see this as something provided by us to the block though. Maybe with a future |
Excellent point. Floats are the worst.
I was specifically thinking of how the Image block currently receives an extra wrapping div when floated — with a meta goal of getting the editor closer to the frontend in markup, leveraging that could be a piece of the puzzle. But did not mean to suggest the current solution isn't good — it seems totally fine. You've eliminated so many divs, it's fine to add one back :D |
Yes, right now, the extra div is needed, but soon we'll be able to remove one more for image (the outer one). worth noting that this adds a div for blocks with alignment but not for the others. :) |
|
||
// For aligned blocks, provide a wrapper element so the block can be | ||
// positioned relative to the block column. | ||
if ( attributes.align ) { |
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 wondering if this is a good way to check whether a block has alignment. For me a more precise way is to check the wrapper props and see if there's a "data-align" because that's how floating is triggered.
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.
Sounds good. I changed it to data-align
.
Description
After #19593, this PR reintroduces a
div
wrapper element for blocks that support alignment. This wrapperdiv
is necessary to contain the aligned block within the main block column. Maybe in the future, the block itself can add this wrapperdiv
, but for now we have to provide it.Note that the wrapper div has the
is-block-content
class. Regardless of how we rewrite alignments, an attribute like this will be necessary so a block can decide where the toolbar should be attached to.How has this been tested?
Test alignments on blocks.
Screenshots
Types of changes
Checklist: