@@ -34,24 +34,24 @@ export const PaginationWidget = ({
34
34
const currentPage = paginationState . context . page
35
35
const numRecordsPerPage = paginationState . context . limit
36
36
37
- const numPages = numRecords
38
- ? Math . ceil ( numRecords / numRecordsPerPage )
39
- : undefined
37
+ const numPages = numRecords ? Math . ceil ( numRecords / numRecordsPerPage ) : 0
40
38
const firstPageActive = currentPage === 1 && numPages !== 0
41
39
const lastPageActive = currentPage === numPages && numPages !== 0
40
+ // if beyond page 1, show pagination widget even if there's only one true page, so user can navigate back
41
+ const showWidget = numPages > 1 || currentPage > 1
42
42
43
43
return (
44
- < div style = { containerStyle } className = { styles . defaultContainerStyles } >
45
- < Button
46
- className = { styles . prevLabelStyles }
47
- aria-label = "Previous page"
48
- disabled = { firstPageActive }
49
- onClick = { ( ) => send ( { type : "PREVIOUS_PAGE" } ) }
50
- >
51
- < KeyboardArrowLeft / >
52
- < div > { prevLabel } </ div >
53
- </ Button >
54
- < Maybe condition = { numPages !== undefined } >
44
+ < Maybe condition = { showWidget } >
45
+ < div style = { containerStyle } className = { styles . defaultContainerStyles } >
46
+ < Button
47
+ className = { styles . prevLabelStyles }
48
+ aria-label = "Previous page"
49
+ disabled = { firstPageActive }
50
+ onClick = { ( ) => send ( { type : "PREVIOUS_PAGE" } ) }
51
+ >
52
+ < KeyboardArrowLeft / >
53
+ < div > { prevLabel } </ div >
54
+ </ Button >
55
55
< ChooseOne >
56
56
< Cond condition = { isMobile } >
57
57
< PageButton
@@ -61,37 +61,36 @@ export const PaginationWidget = ({
61
61
/>
62
62
</ Cond >
63
63
< Cond >
64
- { numPages &&
65
- buildPagedList ( numPages , currentPage ) . map ( ( page ) =>
66
- typeof page !== "number" ? (
67
- < PageButton
68
- key = { `Page${ page } ` }
69
- activePage = { currentPage }
70
- placeholder = "..."
71
- disabled
72
- />
73
- ) : (
74
- < PageButton
75
- key = { `Page${ page } ` }
76
- activePage = { currentPage }
77
- page = { page }
78
- numPages = { numPages }
79
- onPageClick = { ( ) => send ( { type : "GO_TO_PAGE" , page } ) }
80
- />
81
- ) ,
82
- ) }
64
+ { buildPagedList ( numPages , currentPage ) . map ( ( page ) =>
65
+ typeof page !== "number" ? (
66
+ < PageButton
67
+ key = { `Page${ page } ` }
68
+ activePage = { currentPage }
69
+ placeholder = "..."
70
+ disabled
71
+ />
72
+ ) : (
73
+ < PageButton
74
+ key = { `Page${ page } ` }
75
+ activePage = { currentPage }
76
+ page = { page }
77
+ numPages = { numPages }
78
+ onPageClick = { ( ) => send ( { type : "GO_TO_PAGE" , page } ) }
79
+ />
80
+ ) ,
81
+ ) }
83
82
</ Cond >
84
83
</ ChooseOne >
85
- </ Maybe >
86
- < Button
87
- aria-label = "Next page"
88
- disabled = { lastPageActive }
89
- onClick = { ( ) => send ( { type : "NEXT_PAGE" } ) }
90
- >
91
- < div > { nextLabel } </ div >
92
- < KeyboardArrowRight / >
93
- </ Button >
94
- </ div >
84
+ < Button
85
+ aria-label = "Next page"
86
+ disabled = { lastPageActive }
87
+ onClick = { ( ) => send ( { type : "NEXT_PAGE" } ) }
88
+ >
89
+ < div > { nextLabel } </ div >
90
+ < KeyboardArrowRight / >
91
+ </ Button >
92
+ </ div >
93
+ </ Maybe >
95
94
)
96
95
}
97
96
0 commit comments