Skip to content

Commit

Permalink
DataViews: Use SelectControl for selecting a page (#57215)
Browse files Browse the repository at this point in the history
* DataViews: Use SelectControl for selecting a page

* Use compact size

---------

Co-authored-by: James Koster <james@jameskoster.co.uk>
  • Loading branch information
ntsekouras and jameskoster committed Dec 19, 2023
1 parent a76800c commit b653242
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions packages/dataviews/src/pagination.js
Expand Up @@ -4,7 +4,7 @@
import {
Button,
__experimentalHStack as HStack,
__experimentalNumberControl as NumberControl,
SelectControl,
} from '@wordpress/components';
import { createInterpolateElement } from '@wordpress/element';
import { sprintf, __, _x } from '@wordpress/i18n';
Expand Down Expand Up @@ -40,28 +40,23 @@ function Pagination( {
),
{
CurrenPageControl: (
<NumberControl
<SelectControl
aria-label={ __( 'Current page' ) }
min={ 1 }
max={ totalPages }
onChange={ ( value ) => {
const _value = +value;
if (
! _value ||
_value < 1 ||
_value > totalPages
) {
return;
}
value={ view.page }
options={ Array.from(
Array( totalPages )
).map( ( _, i ) => {
const page = i + 1;
return { value: page, label: page };
} ) }
onChange={ ( newValue ) => {
onChangeView( {
...view,
page: _value,
page: +newValue,
} );
} }
step="1"
value={ view.page }
isDragEnabled={ false }
spinControls="none"
size={ 'compact' }
__nextHasNoMarginBottom
/>
),
}
Expand Down

0 comments on commit b653242

Please sign in to comment.