Skip to content

Commit

Permalink
Prevent entering invalid values in the Query Loop block config (#33285)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jul 12, 2021
1 parent 0365552 commit bb010c1
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions packages/block-library/src/query/edit/query-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,18 @@ export default function QueryToolbar( {
labelPosition="edge"
min={ 1 }
max={ 100 }
onChange={ ( value ) =>
onChange={ ( value ) => {
if (
isNaN( value ) ||
value < 1 ||
value > 100
) {
return;
}
setQuery( {
perPage: +value ?? -1,
} )
}
perPage: value,
} );
} }
step="1"
value={ query.perPage }
isDragEnabled={ false }
Expand All @@ -78,9 +85,16 @@ export default function QueryToolbar( {
labelPosition="edge"
min={ 0 }
max={ 100 }
onChange={ ( value ) =>
setQuery( { offset: +value } )
}
onChange={ ( value ) => {
if (
isNaN( value ) ||
value < 0 ||
value > 100
) {
return;
}
setQuery( { offset: value } );
} }
step="1"
value={ query.offset }
isDragEnabled={ false }
Expand All @@ -98,9 +112,12 @@ export default function QueryToolbar( {
label={ __( 'Max page to show' ) }
labelPosition="edge"
min={ 0 }
onChange={ ( value ) =>
setQuery( { pages: +value } )
}
onChange={ ( value ) => {
if ( isNaN( value ) || value < 0 ) {
return;
}
setQuery( { pages: value } );
} }
step="1"
value={ query.pages }
isDragEnabled={ false }
Expand Down

0 comments on commit bb010c1

Please sign in to comment.