From 161e000ca85d6a4442406d7e0aaa42cd8d2d153a Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Thu, 8 Jul 2021 12:46:26 +0100 Subject: [PATCH] Prevent entering invalid values in the Query Loop block config --- .../src/query/edit/query-toolbar.js | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/packages/block-library/src/query/edit/query-toolbar.js b/packages/block-library/src/query/edit/query-toolbar.js index db4de14f297b19..92db79c7dad7b2 100644 --- a/packages/block-library/src/query/edit/query-toolbar.js +++ b/packages/block-library/src/query/edit/query-toolbar.js @@ -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 } @@ -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 } @@ -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 }