Skip to content

Commit 772176a

Browse files
authored
fix(material/paginator): allow readonly options (#24054)
closes #24050
1 parent 667a555 commit 772176a

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

src/material-experimental/mdc-paginator/paginator.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,13 @@ describe('MDC-based MatPaginator', () => {
511511
const hostElement = fixture.nativeElement.querySelector('mat-paginator');
512512
expect(hostElement.getAttribute('role')).toBe('group');
513513
});
514+
515+
it('should handle the page size options input being passed in as readonly array', () => {
516+
const fixture = createComponent(MatPaginatorWithReadonlyOptions);
517+
fixture.detectChanges();
518+
519+
expect(fixture.componentInstance.paginator._displayedPageSizeOptions).toEqual([5, 10, 25, 100]);
520+
});
514521
});
515522

516523
function getPreviousButton(fixture: ComponentFixture<any>) {
@@ -600,3 +607,14 @@ class MatPaginatorWithoutOptionsApp {
600607
class MatPaginatorWithStringValues {
601608
@ViewChild(MatPaginator) paginator: MatPaginator;
602609
}
610+
611+
@Component({
612+
template: `
613+
<mat-paginator [pageSizeOptions]="pageSizeOptions">
614+
</mat-paginator>
615+
`,
616+
})
617+
class MatPaginatorWithReadonlyOptions {
618+
@ViewChild(MatPaginator) paginator: MatPaginator;
619+
pageSizeOptions: readonly number[] = [5, 10, 25, 100];
620+
}

src/material/paginator/paginator.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,13 @@ describe('MatPaginator', () => {
506506
const hostElement = fixture.nativeElement.querySelector('mat-paginator');
507507
expect(hostElement.getAttribute('role')).toBe('group');
508508
});
509+
510+
it('should handle the page size options input being passed in as readonly array', () => {
511+
const fixture = createComponent(MatPaginatorWithReadonlyOptions);
512+
fixture.detectChanges();
513+
514+
expect(fixture.componentInstance.paginator._displayedPageSizeOptions).toEqual([5, 10, 25, 100]);
515+
});
509516
});
510517

511518
function getPreviousButton(fixture: ComponentFixture<any>) {
@@ -595,3 +602,14 @@ class MatPaginatorWithoutOptionsApp {
595602
class MatPaginatorWithStringValues {
596603
@ViewChild(MatPaginator) paginator: MatPaginator;
597604
}
605+
606+
@Component({
607+
template: `
608+
<mat-paginator [pageSizeOptions]="pageSizeOptions">
609+
</mat-paginator>
610+
`,
611+
})
612+
class MatPaginatorWithReadonlyOptions {
613+
@ViewChild(MatPaginator) paginator: MatPaginator;
614+
pageSizeOptions: readonly number[] = [5, 10, 25, 100];
615+
}

src/material/paginator/paginator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export abstract class _MatPaginatorBase<
149149
get pageSizeOptions(): number[] {
150150
return this._pageSizeOptions;
151151
}
152-
set pageSizeOptions(value: number[]) {
152+
set pageSizeOptions(value: number[] | readonly number[]) {
153153
this._pageSizeOptions = (value || []).map(p => coerceNumberProperty(p));
154154
this._updateDisplayedPageSizeOptions();
155155
}

tools/public_api_guard/material/paginator.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export abstract class _MatPaginatorBase<O extends {
8383
get pageSize(): number;
8484
set pageSize(value: NumberInput);
8585
get pageSizeOptions(): number[];
86-
set pageSizeOptions(value: number[]);
86+
set pageSizeOptions(value: number[] | readonly number[]);
8787
_previousButtonsDisabled(): boolean;
8888
previousPage(): void;
8989
get showFirstLastButtons(): boolean;

0 commit comments

Comments
 (0)