Skip to content
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

Disallow setting grid block rows/columns to zero #65217

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Changes from all 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
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what was incorrectly causing 0 to be rendered

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
Loading