Skip to content

Commit

Permalink
Disallow setting grid block rows/columns to zero (#65217)
Browse files Browse the repository at this point in the history
* Disallow setting grid block rows/columns to zero

* Prevent issues with grid block column/row count by ensuring a proper minimum

Co-authored-by: talldan <talldanwp@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
  • Loading branch information
4 people committed Sep 11, 2024
1 parent 98c65ea commit da8f874
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/block-editor/src/layouts/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export default {
// In the experiment we want to also show column control in Auto mode, and
// the minimum width control in Manual mode.
const showColumnsControl =
window.__experimentalEnableGridInteractivity || layout?.columnCount;
window.__experimentalEnableGridInteractivity ||
!! layout?.columnCount;
const showMinWidthControl =
window.__experimentalEnableGridInteractivity ||
! layout?.columnCount;
Expand Down Expand Up @@ -317,7 +318,7 @@ function GridLayoutColumnsAndRowsControl( {
const defaultNewColumnCount =
isManualPlacement ? 1 : undefined;
const newColumnCount =
value === ''
value === '' || value === '0'
? defaultNewColumnCount
: parseInt( value, 10 );
onChange( {
Expand All @@ -327,7 +328,7 @@ function GridLayoutColumnsAndRowsControl( {
} else {
// Don't allow unsetting the column count.
const newColumnCount =
value === ''
value === '' || value === '0'
? 1
: parseInt( value, 10 );
onChange( {
Expand All @@ -337,7 +338,7 @@ function GridLayoutColumnsAndRowsControl( {
}
} }
value={ columnCount }
min={ 0 }
min={ 1 }
label={ __( 'Columns' ) }
hideLabelFromVision={
! window.__experimentalEnableGridInteractivity ||
Expand All @@ -355,7 +356,7 @@ function GridLayoutColumnsAndRowsControl( {
onChange={ ( value ) => {
// Don't allow unsetting the row count.
const newRowCount =
value === ''
value === '' || value === '0'
? 1
: parseInt( value, 10 );
onChange( {
Expand All @@ -364,21 +365,24 @@ function GridLayoutColumnsAndRowsControl( {
} );
} }
value={ rowCount }
min={ 0 }
min={ 1 }
label={ __( 'Rows' ) }
/>
) : (
<RangeControl
__next40pxDefaultSize
__nextHasNoMarginBottom
value={ columnCount ?? 0 }
value={ columnCount ?? 1 }
onChange={ ( value ) =>
onChange( {
...layout,
columnCount: value,
columnCount:
value === '' || value === '0'
? 1
: value,
} )
}
min={ 0 }
min={ 1 }
max={ 16 }
withInputField={ false }
label={ __( 'Columns' ) }
Expand Down

0 comments on commit da8f874

Please sign in to comment.