-
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
Fix resizing items to top and left with GridItemResizer #60986
Conversation
Size Change: +2.52 kB (+0.14%) Total Size: 1.74 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. |
Hmm, tricky. Would be good to get some design input. @jasmussen: Is there anyone in particular I should ping for grid design work while @SaxonF is away? 😀 I am thinking it probably doesn't make sense to have resizing to the top and left unless the item can also be positioned manually. |
Saxon is hard to replace, since he was so close to this grid work. I'll give this a quick shot now, and I'm always happy to be pinged. But also in general, the easiest is to ping @WordPress/gutenberg-design, that'll ping a bunch of useful folks that can likely provide good input. |
Thanks for the thorough feedback and testing @jasmussen!
This should be fixed now. The resizer shouldn't stick anymore, but I also experimented with removing the resizers from the edges. Let me know if that improves things!
This is a tough one. Rearranging a grid to have less empty space in it would involve either deliberately positioning items with a column/row start, or adding something like Replacing the dashed cell indication with opacity should be easy to do. Rob's tried something like that out already in #61025, but given that one's extremely unlikely to ship in 6.6 at this point, perhaps we can move it out. Either way I think it's a good candidate for its own PR, to try and keep this one (relatively) simple for review 😅 |
Nice work. This is feeling very much better than trunk, and rapidly approaching something very solid. I would appreciate reviews from as many others as you can, especially folks familiar with grid, so we can approve this one. The stickiness seems addressed, and the contextual resizing handles feels like it's working well, and as intended. All of that, captured in this GIF below: I did encounter one curiosity in that GIF above, hard to describe, but I resized a row upwards, and the first couple of resizes didn't take, and the third one seemed to suddenly create a bunch more rows than I was expecting. It's not clear it was a bug or not. And snapping, though likely very tricky to get right, may help here. |
I can reproduce this locally, pretty sure it's a bug 😅 |
This is indeed a bug. The problem is that in certain grid configurations, increasing the number of rows on an element at the edges of the grid won't change its overall size. The GridVisualizer component is observing window resizing in order to know when to make changes to the grid, but because no block dimensions change, there's no way of observing an extra row getting added. This could potentially be fixed by #61383, which by making sure auto rows always have a minimum height, will almost always trigger some change to the grid dimensions. I'm open to other ideas though! |
bottom: 'flex-start', | ||
}; | ||
|
||
const styles = { |
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.
What do you think about doing this with a CSS classname instead of a styles
object? BlockPopoverCover
could have a .block-popover-cover
and .block-popover-cover__cover
class and .block-editor-grid-item-resizer
could have .is-right-justified
and .is-top-aligned
variations.
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 mean we could do that but is there any advantage to it? Using styles
is more consistent with how the component works, like with the width
and height
props.
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.
It lets us avoid adding the new additionalStyles
prop. Not a big deal since BlockPopoverCover
is not a public component but nice to keep API surface area low where possible. Up to you.
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.
Hmm yeah. I think the additional prop is a worthwhile trade-off for better legibility. Also the inline style means it's less likely some over-specific CSS will break this at any point 😄
* The mouseup event on the resize handle doesn't trigger if the mouse | ||
* isn't directly above the handle, so we try to detect if it happens | ||
* outside the grid and dispatch a mouseup event on the handle. | ||
*/ |
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.
Should this fix live in ResizableBox
so that future users of the component don't run into the same issue?
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.
Hmm good question. This issue only surfaces when we set bounds
on the box, so it's not really useful for all the instances. And this fix depends on knowing about a parent element, which ResizableBox
doesn't. It doesn't even implement its own onResizeStart
, just passes it directly to Resizable
. So I'm not sure it's worth adding complexity to the component for what so far is a pretty niche use case. Maybe worth doing it if similar instances pop up in other places?
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.
The mouseup
handler could be added to ownerWindow
or ownerDocument
to avoid it having to know about a parent element.
But yeah, not sure if it's needed in ResizableBox
, up to you.
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.
Hmmm not sure that'll work if we have the iframe in the way. The parent element I added the event listener to is in the actual editor canvas, but the component isn't.
packages/block-editor/src/components/grid-visualizer/grid-item-resizer.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/grid-visualizer/grid-item-resizer.js
Show resolved
Hide resolved
Maybe I don't think we can use a |
Yeah looks like there's no observer that can be used in this context. I think we can leave this issue for a separate PR though, because it's an existing one (can be reproduced on trunk by changing the Row count for a top or bottom block in the sidebar control). If we do decide to ship #61383, it'll be solved, otherwise I'm sure we'll think of something. |
48ae9b0
to
19e8ae2
Compare
The handles don't show/hide when the position of the element changes because of a resize: Kapture.2024-05-10.at.14.48.40.mp4 |
* outside the grid and dispatch a mouseup event on the handle. | ||
*/ | ||
const rootElementParent = rootBlockElement.parentElement; | ||
rootElementParent.addEventListener( |
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.
We need to remove this event listener somewhere to avoid memory leaks.
packages/block-editor/src/components/grid-visualizer/grid-item-resizer.js
Outdated
Show resolved
Hide resolved
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.
What?
Part of #57478.
Updates the GridItemResizer to allow resizing by dragging the block to the top and left. Because the resizing doesn't position the block on a specific column/row, most often resizing to the top or left will result in the block growing to the bottom or right, as it keeps its auto-placement in the grid.
I'm not sure we should meddle with auto-placement in auto mode, but in manual mode there's scope to possibly add a column/row start value to a resized block so it sticks to the area the resizer has been dragged to. I think that given the ongoing work around positioning in manual mode (see #61025) this PR could be merged as it stands (pending review of course) and placement worked on as a follow-up.
Feedback on all this is very welcome!
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast
resizing-left.mov