fix(paginator): handle negative pageSize and pageIndex correctly (#11068)

This commit is contained in:
Kristiyan Kostadinov
2018-05-01 10:35:04 -04:00
committed by Joey Perrott
parent 01d0993993
commit 3f5e481e32
2 changed files with 12 additions and 2 deletions
+10
View File
@@ -157,6 +157,16 @@ describe('MatPaginator', () => {
expect(isMarkedInitialized).toBeTruthy();
}));
it('should not allow a negative pageSize', () => {
paginator.pageSize = -1337;
expect(paginator.pageSize).toBeGreaterThanOrEqual(0);
});
it('should not allow a negative pageIndex', () => {
paginator.pageSize = -42;
expect(paginator.pageIndex).toBeGreaterThanOrEqual(0);
});
describe('when showing the first and last button', () => {
beforeEach(() => {
+2 -2
View File
@@ -76,7 +76,7 @@ export class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy
@Input()
get pageIndex(): number { return this._pageIndex; }
set pageIndex(value: number) {
this._pageIndex = coerceNumberProperty(value);
this._pageIndex = Math.max(coerceNumberProperty(value), 0);
this._changeDetectorRef.markForCheck();
}
_pageIndex: number = 0;
@@ -94,7 +94,7 @@ export class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy
@Input()
get pageSize(): number { return this._pageSize; }
set pageSize(value: number) {
this._pageSize = coerceNumberProperty(value);
this._pageSize = Math.max(coerceNumberProperty(value), 0);
this._updateDisplayedPageSizeOptions();
}
private _pageSize: number;