Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Prevent entering invalid values in the Query Loop block config (#33285)
  • Loading branch information
youknowriad committed Jul 12, 2021
commit bb010c16bc794d90e69430e88f4255351693c94e
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