Skip to content

Commit 1324e37

Browse files
liammannmcosta74
authored andcommitted
fix(pagination) Keep start page number (edcarroll#286)
* fix(pagination) Keep start page number * Update pageCount inside collectionSize * Move pageSize above collectionSize setter * remove trailing whitespace
1 parent 1cebf2a commit 1324e37

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/collections/pagination/components/pagination.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,14 @@ describe("Pagination", () => {
196196
expect(pagination.pages.length).toBe(5);
197197
expect(pagination.hasNavigationLinks).toBe(true);
198198
});
199+
it("should keep the start page number", () => {
200+
comp.collectionSize = 100;
201+
comp.pageSize = 10;
202+
comp.maxSize = 5;
203+
comp.currentPage = 5;
204+
205+
fixture.detectChanges();
206+
expect(comp.currentPage).toBe(5);
207+
expect(pagination.page).toBe(5);
208+
});
199209
});

src/collections/pagination/components/pagination.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,19 @@ export class SuiPagination implements OnChanges {
6666
this._maxSize = (value != undefined) ? Math.max(value, 1) : undefined;
6767
}
6868

69+
@Input()
70+
public pageSize:number;
71+
6972
@Input()
7073
public get collectionSize():number {
7174
return this._collectionSize;
7275
}
7376

7477
public set collectionSize(value:number) {
7578
this._collectionSize = Math.max(value, 0);
79+
this.pageCount = Math.max(1, Math.ceil(this._collectionSize / this.pageSize));
7680
}
7781

78-
@Input()
79-
public pageSize:number;
80-
8182
@Input()
8283
public get hasNavigationLinks():boolean {
8384
const maxSize = this._maxSize || this.pageCount;

0 commit comments

Comments
 (0)