File tree 5 files changed +14
-9
lines changed
5 files changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ test('displays an out of range page', () => {
93
93
items : processed ,
94
94
pagesCount,
95
95
actualPageIndex,
96
- } = processItems ( items , { currentPageIndex : 3 } , { pagination : { } } ) ;
96
+ } = processItems ( items , { currentPageIndex : 3 } , { pagination : { allowPageOutOfRange : true } } ) ;
97
97
expect ( actualPageIndex ) . toEqual ( 3 ) ;
98
98
expect ( pagesCount ) . toEqual ( 2 ) ;
99
99
expect ( processed ) . toHaveLength ( 0 ) ;
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ export interface UseCollectionOptions<T> {
44
44
freeTextFiltering ?: PropertyFilterFreeTextFiltering ;
45
45
} ;
46
46
sorting ?: { defaultState ?: SortingState < T > } ;
47
- pagination ?: { defaultPage ?: number ; pageSize ?: number } ;
47
+ pagination ?: { defaultPage ?: number ; pageSize ?: number ; allowPageOutOfRange ?: boolean } ;
48
48
selection ?: {
49
49
defaultSelectedItems ?: ReadonlyArray < T > ;
50
50
keepSelection ?: boolean ;
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ export function createPageProps<T>(
16
16
const pageSize = pagination . pageSize ?? DEFAULT_PAGE_SIZE ;
17
17
const pagesCount = Math . ceil ( items . length / pageSize ) ;
18
18
let pageIndex = currentPageIndex ?? 1 ;
19
- if ( pageIndex < 1 || Number . isNaN ( pageIndex ) ) {
19
+ if ( pageIndex < 1 || ( pageIndex > pagesCount && ! pagination . allowPageOutOfRange ) || Number . isNaN ( pageIndex ) ) {
20
20
pageIndex = 1 ;
21
21
}
22
22
return { pageSize, pagesCount, pageIndex } ;
Original file line number Diff line number Diff line change 5
5
* subset of node.js types, safe to use in browser and bundlers
6
6
* we do not use `lib.dom` types because they are not available in SSR environment
7
7
*/
8
- declare const process : { env : { NODE_ENV ?: string } } ;
9
- declare const console : { warn : ( ...args : Array < any > ) => void } ;
8
+ declare global {
9
+ const process : { env : { NODE_ENV ?: string } } ;
10
+ const console : { warn : ( ...args : Array < any > ) => void } ;
11
+ }
12
+
13
+ // dummy export to make typescript treat this file as ES module
14
+ export { } ;
Original file line number Diff line number Diff line change @@ -84,22 +84,22 @@ export function createActions<T>({
84
84
return {
85
85
setFiltering ( filteringText ) {
86
86
dispatch ( { type : 'filtering' , filteringText } ) ;
87
- collectionRef . current && collectionRef . current . scrollToTop ( ) ;
87
+ collectionRef . current ? .scrollToTop ( ) ;
88
88
} ,
89
89
setSorting ( state : SortingState < T > ) {
90
90
dispatch ( { type : 'sorting' , sortingState : state } ) ;
91
- collectionRef . current && collectionRef . current . scrollToTop ( ) ;
91
+ collectionRef . current ? .scrollToTop ( ) ;
92
92
} ,
93
93
setCurrentPage ( pageIndex : number ) {
94
94
dispatch ( { type : 'pagination' , pageIndex } ) ;
95
- collectionRef . current && collectionRef . current . scrollToTop ( ) ;
95
+ collectionRef . current ? .scrollToTop ( ) ;
96
96
} ,
97
97
setSelectedItems ( selectedItems : Array < T > ) {
98
98
dispatch ( { type : 'selection' , selectedItems } ) ;
99
99
} ,
100
100
setPropertyFiltering ( query : PropertyFilterQuery ) {
101
101
dispatch ( { type : 'property-filtering' , query } ) ;
102
- collectionRef . current && collectionRef . current . scrollToTop ( ) ;
102
+ collectionRef . current ? .scrollToTop ( ) ;
103
103
} ,
104
104
setExpandedItems ( expandedItems : ReadonlyArray < T > ) {
105
105
dispatch ( { type : 'expansion' , expandedItems } ) ;
You can’t perform that action at this time.
0 commit comments