-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[Type] Enhancement - Adds max limit to row span and column span in grid. #64895
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
Conversation
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. |
Makes sense to me :) |
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.
Thanks for the PR!
Unfortunately, #63967 is lacking some context in its description 😬 This issue mostly applies to the experimental grid functionality behind the experiment flag.
To enable it, go to "Experiments" under the "Gutenberg" wp-admin menu item.
To see it in the code, look at where we're checking for window.__experimentalEnableGridInteractivity
being enabled.
As mentioned in the comments below, I think we could use the column span constraint in stable grid when a columnCount exists, but not otherwise.
The row span constraint doesn't make sense outside of the experiment flag, as we can't currently set row count in stable.
A general purpose tip for submitting PRs in Gutenberg:
Make sure you manually test your changes in your local development environment before submitting the PR. Some of the issues I'm seeing in this PR could have easily been detected by testing the changes in a block with grid layout against its current state in trunk.
If you're implementing something as described in an issue (as I'm guessing was the case here!) and in testing it doesn't seem to work that well, feel free to start a discussion about it on the issue. Sometimes things we think might work don't in practice! And that's OK. It just means we need to think about it some more.
And a small workflow tip 🙂
"Feat" isn't used as a PR descriptor in this repo. We use GitHub labels instead: "[Type] Feature" labels for major features only, "[Type] Enhancement" for small improvements such as this one, or "[Type] Bug" for stuff that's broken.
min={ 1 } | ||
/> | ||
</HStack> | ||
<FlexItem style={ { width: '50%' } }> |
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 change from HStack
to Flex
and FlexItem
? HStack
uses less markup to the same effect.
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.
: Math.min( | ||
parseInt( value, 10 ), | ||
maxColumnSpan | ||
); |
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 should only set a maxColumnSpan
if the columnCount
exists. Otherwise, when the grid is in auto mode and can have as many columns as fit on the screen, it won't be possible to increase the column count beyond 3.
value === '' | ||
? 1 | ||
: Math.min( | ||
parseInt( value, 10 ), |
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 don't believe we should set a maxRowSpan unless it's for manual mode under the experimental flag, because in the current stable grid it's not possible to set a row count. This effectively means that items will never be able to span more than one row.
Hi @tellthemachines, Thank you so much for the review. 🙇 I’ve updated the PR. I also noticed that when we set the Should we check against the screencast.mp4 |
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.
Thanks for persisting with this! It looks pretty close, but I found a small bug. Details in the comment below.
@@ -235,53 +234,78 @@ function GridControls( { | |||
} ); | |||
}; | |||
|
|||
// Calculate max column span based on current position and grid width | |||
const maxColumnSpan = columnCount | |||
? columnCount - ( columnStart ?? 1 ) + 1 |
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.
columnCount
is always going to exist here because we're setting a default value of 3 when we get it from parentLayout
above. The problem with that is in auto layouts with no columnCount defined, we're now unable to set a columnCount above 3 on child blocks.
I think we'll have to remove that default value in order to fix this, and maybe pass it instead to useGetNumberOfBlocksBeforeCell
if columnCount
is undefined.
We should also remove columnCount
from the condition that allows the grid placement controls to display below (that shouldn't make a difference because columnCount
is always true currently).
(Later we might want to consider not displaying the grid placement controls for children of auto grids, but that can be done in another PR)
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.
Since we've now removed the default columnCount
, the grid placement controls in Auto mode are no longer visible, after removing the columnCount
check for their visibility. So, this change has been included in the same PR.
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.
Thanks for the update, changes LGTM!
CI failures seem unrelated to the PR so they should go away if you rebase this branch. Are you able to do that?
Sure @tellthemachines |
What?
Fixes: #63967
Why?
There was no maximum limit set for row span and column span, allowing users to set values larger than the actual number of rows or columns.
How?
It calculates the max column and row span based on the columns/row count and current position.
Testing Instructions
Screenshots or screencast
Screen.Recording.2024-08-29.at.2.31.25.PM.mov