Skip to content

fix(material/paginator): allow readonly options (#24050) #24054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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