Skip to content

Commit

Permalink
Set minimum value if no value in input and accommodate range controls…
Browse files Browse the repository at this point in the history
…'s peculiarities.
  • Loading branch information
tellthemachines committed Feb 19, 2024
1 parent a392d82 commit e1a08ec
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/block-editor/src/layouts/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,17 @@ function GridLayoutColumnsControl( { layout, onChange } ) {
<FlexItem isBlock>
<NumberControl
size={ '__unstable-large' }
onChange={ ( value ) =>
onChange={ ( value ) => {
/**
* If the input is cleared, avoid switching
* back to "Auto" by setting a value of "1".
*/
const validValue = value !== '' ? value : '1';
onChange( {
...layout,
columnCount: value,
} )
}
columnCount: validValue,
} );
} }
value={ columnCount }
min={ 1 }
label={ __( 'Columns' ) }
Expand All @@ -248,7 +253,7 @@ function GridLayoutColumnsControl( { layout, onChange } ) {
</FlexItem>
<FlexItem isBlock>
<RangeControl
value={ columnCount }
value={ parseInt( columnCount, 10 ) } // RangeControl can't deal with strings.
onChange={ ( value ) =>
onChange( {
...layout,
Expand Down

0 comments on commit e1a08ec

Please sign in to comment.