Skip to content

Commit

Permalink
fix(material/paginator): allow readonly options (#24054)
Browse files Browse the repository at this point in the history
closes #24050

(cherry picked from commit 772176a)
  • Loading branch information
lekhmanrus authored and andrewseguin committed Jan 18, 2022
1 parent a413e30 commit a4f6558
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/material-experimental/mdc-paginator/paginator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,13 @@ describe('MDC-based MatPaginator', () => {
const hostElement = fixture.nativeElement.querySelector('mat-paginator');
expect(hostElement.getAttribute('role')).toBe('group');
});

it('should handle the page size options input being passed in as readonly array', () => {
const fixture = createComponent(MatPaginatorWithReadonlyOptions);
fixture.detectChanges();

expect(fixture.componentInstance.paginator._displayedPageSizeOptions).toEqual([5, 10, 25, 100]);
});
});

function getPreviousButton(fixture: ComponentFixture<any>) {
Expand Down Expand Up @@ -600,3 +607,14 @@ class MatPaginatorWithoutOptionsApp {
class MatPaginatorWithStringValues {
@ViewChild(MatPaginator) paginator: MatPaginator;
}

@Component({
template: `
<mat-paginator [pageSizeOptions]="pageSizeOptions">
</mat-paginator>
`,
})
class MatPaginatorWithReadonlyOptions {
@ViewChild(MatPaginator) paginator: MatPaginator;
pageSizeOptions: readonly number[] = [5, 10, 25, 100];
}
18 changes: 18 additions & 0 deletions src/material/paginator/paginator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,13 @@ describe('MatPaginator', () => {
const hostElement = fixture.nativeElement.querySelector('mat-paginator');
expect(hostElement.getAttribute('role')).toBe('group');
});

it('should handle the page size options input being passed in as readonly array', () => {
const fixture = createComponent(MatPaginatorWithReadonlyOptions);
fixture.detectChanges();

expect(fixture.componentInstance.paginator._displayedPageSizeOptions).toEqual([5, 10, 25, 100]);
});
});

function getPreviousButton(fixture: ComponentFixture<any>) {
Expand Down Expand Up @@ -595,3 +602,14 @@ class MatPaginatorWithoutOptionsApp {
class MatPaginatorWithStringValues {
@ViewChild(MatPaginator) paginator: MatPaginator;
}

@Component({
template: `
<mat-paginator [pageSizeOptions]="pageSizeOptions">
</mat-paginator>
`,
})
class MatPaginatorWithReadonlyOptions {
@ViewChild(MatPaginator) paginator: MatPaginator;
pageSizeOptions: readonly number[] = [5, 10, 25, 100];
}
2 changes: 1 addition & 1 deletion src/material/paginator/paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export abstract class _MatPaginatorBase<
get pageSizeOptions(): number[] {
return this._pageSizeOptions;
}
set pageSizeOptions(value: number[]) {
set pageSizeOptions(value: number[] | readonly number[]) {
this._pageSizeOptions = (value || []).map(p => coerceNumberProperty(p));
this._updateDisplayedPageSizeOptions();
}
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/material/paginator.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export abstract class _MatPaginatorBase<O extends {
get pageSize(): number;
set pageSize(value: NumberInput);
get pageSizeOptions(): number[];
set pageSizeOptions(value: number[]);
set pageSizeOptions(value: number[] | readonly number[]);
_previousButtonsDisabled(): boolean;
previousPage(): void;
get showFirstLastButtons(): boolean;
Expand Down

0 comments on commit a4f6558

Please sign in to comment.