Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
__experimentalUnitControl as UnitControl,
__experimentalInputControl as InputControl,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
__experimentalToolsPanelItem as ToolsPanelItem,
Flex,
Expand Down Expand Up @@ -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%' } }>

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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 max attribute 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.

image

<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
);

Copy link
Copy Markdown
Contributor

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.

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 ),

Copy link
Copy Markdown
Contributor

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.

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
Expand Down