Repository navigation
[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
Changes from 2 commits
f4b1fcf
a9c8f32
e11923e
3e86284
4d4df6e
6255f74
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 |
|---|---|---|
|
|
@@ -6,7 +6,6 @@ import { | |
| __experimentalToggleGroupControlOption as ToggleGroupControlOption, | ||
| __experimentalUnitControl as UnitControl, | ||
| __experimentalInputControl as InputControl, | ||
| __experimentalHStack as HStack, | ||
| __experimentalVStack as VStack, | ||
| __experimentalToolsPanelItem as ToolsPanelItem, | ||
| Flex, | ||
|
|
@@ -220,53 +219,75 @@ function GridControls( { | |
| } ); | ||
| }; | ||
|
|
||
| // Calculate max column span based on current position and grid width | ||
| const maxColumnSpan = ( columnCount ?? 3 ) - ( columnStart ?? 1 ) + 1; | ||
|
|
||
| // Calculate max row span based on current position and grid height | ||
| const maxRowSpan = ( rowCount ?? 1 ) - ( rowStart ?? 1 ) + 1; | ||
|
|
||
| return ( | ||
| <> | ||
| <HStack | ||
| <Flex | ||
| as={ ToolsPanelItem } | ||
| hasValue={ hasSpanValue } | ||
| label={ __( 'Grid span' ) } | ||
| onDeselect={ resetGridSpans } | ||
| isShownByDefault={ isShownByDefault } | ||
| panelId={ panelId } | ||
| > | ||
| <InputControl | ||
| size="__unstable-large" | ||
| label={ __( 'Column span' ) } | ||
| type="number" | ||
| onChange={ ( value ) => { | ||
| // Don't allow unsetting. | ||
| const newColumnSpan = | ||
| value === '' ? 1 : parseInt( value, 10 ); | ||
| onChange( { | ||
| columnStart, | ||
| rowStart, | ||
| rowSpan, | ||
| columnSpan: newColumnSpan, | ||
| } ); | ||
| } } | ||
| value={ columnSpan ?? 1 } | ||
| min={ 1 } | ||
| /> | ||
| <InputControl | ||
| size="__unstable-large" | ||
| label={ __( 'Row span' ) } | ||
| type="number" | ||
| onChange={ ( value ) => { | ||
| // Don't allow unsetting. | ||
| const newRowSpan = | ||
| value === '' ? 1 : parseInt( value, 10 ); | ||
| onChange( { | ||
| columnStart, | ||
| rowStart, | ||
| columnSpan, | ||
| rowSpan: newRowSpan, | ||
| } ); | ||
| } } | ||
| value={ rowSpan ?? 1 } | ||
| min={ 1 } | ||
| /> | ||
| </HStack> | ||
| <FlexItem style={ { width: '50%' } }> | ||
| <InputControl | ||
| size="__unstable-large" | ||
| label={ __( 'Column span' ) } | ||
| type="number" | ||
| onChange={ ( value ) => { | ||
| // Don't allow unsetting. | ||
| const newColumnSpan = | ||
| value === '' | ||
| ? 1 | ||
| : Math.min( | ||
| parseInt( value, 10 ), | ||
| maxColumnSpan | ||
| ); | ||
|
Contributor
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. We should only set a |
||
| onChange( { | ||
| columnStart, | ||
| rowStart, | ||
| rowSpan, | ||
| columnSpan: newColumnSpan, | ||
| } ); | ||
| } } | ||
| value={ columnSpan ?? 1 } | ||
| min={ 1 } | ||
| max={ maxColumnSpan } | ||
| /> | ||
| </FlexItem> | ||
| <FlexItem style={ { width: '50%' } }> | ||
| <InputControl | ||
| size="__unstable-large" | ||
| label={ __( 'Row span' ) } | ||
| type="number" | ||
| onChange={ ( value ) => { | ||
| // Don't allow unsetting. | ||
| const newRowSpan = | ||
| value === '' | ||
| ? 1 | ||
| : Math.min( | ||
| parseInt( value, 10 ), | ||
|
Contributor
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 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. |
||
| maxRowSpan | ||
| ); | ||
| onChange( { | ||
| columnStart, | ||
| rowStart, | ||
| columnSpan, | ||
| rowSpan: newRowSpan, | ||
| } ); | ||
| } } | ||
| value={ rowSpan ?? 1 } | ||
| min={ 1 } | ||
| max={ maxRowSpan } | ||
| /> | ||
| </FlexItem> | ||
| </Flex> | ||
| { window.__experimentalEnableGridInteractivity && columnCount && ( | ||
| // Use Flex with an explicit width on the FlexItem instead of HStack to | ||
| // work around an issue in webkit where inputs with a max attribute are | ||
|
|
||
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
HStacktoFlexandFlexItem?HStackuses 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.
I tried, but by using the
maxattribute it wasn’t applying the size as expected. So, I followed a similar approach to the one Robert used in the Grid Placement section below.