File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed
packages/react/src/DataTable Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @primer/react " : patch
3
+ ---
4
+
5
+ Update data table pagination pageEnd to handle zero based index
Original file line number Diff line number Diff line change @@ -367,7 +367,7 @@ type RangeProps = {
367
367
368
368
function Range ( { pageStart, pageEnd, totalCount} : RangeProps ) {
369
369
const start = pageStart + 1
370
- const end = pageEnd === totalCount - 1 ? totalCount : pageEnd
370
+ const end = pageEnd
371
371
return (
372
372
< >
373
373
< Message value = { `Showing ${ start } through ${ end } of ${ totalCount } ` } />
@@ -524,7 +524,7 @@ function usePagination(config: PaginationConfig): PaginationResult {
524
524
onChange ?.( { pageIndex : defaultPageIndex } )
525
525
}
526
526
const pageStart = pageIndex * pageSize
527
- const pageEnd = Math . min ( pageIndex * pageSize + pageSize , totalCount - 1 )
527
+ const pageEnd = Math . min ( ( pageIndex + 1 ) * pageSize , totalCount )
528
528
const hasNextPage = pageIndex + 1 < pageCount
529
529
const hasPreviousPage = pageIndex > 0
530
530
Original file line number Diff line number Diff line change @@ -116,6 +116,14 @@ describe('Table.Pagination', () => {
116
116
expect ( getPageRange ( ) ) . toEqual ( '1 through 25 of 50' )
117
117
} )
118
118
119
+ it ( 'should display two pages with correct range when totalCount is one plus pageSize' , ( ) => {
120
+ render ( < Pagination aria-label = "Test label" pageSize = { 25 } totalCount = { 26 } /> )
121
+
122
+ expect ( getPages ( ) ) . toHaveLength ( 2 )
123
+ expect ( getCurrentPage ( ) ) . toEqual ( getPage ( 0 ) )
124
+ expect ( getPageRange ( ) ) . toEqual ( '1 through 25 of 26' )
125
+ } )
126
+
119
127
it ( 'should call `onChange` when clicking on pages' , async ( ) => {
120
128
const user = userEvent . setup ( )
121
129
const onChange = jest . fn ( )
You can’t perform that action at this time.
0 commit comments