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 authored and sarayourfriend committed Jul 15, 2021
1 parent 25256a0 commit 41235ee
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 41235ee

Please sign in to comment.