Skip to content

Commit 191d116

Browse files
committed
feat(paginator): add input for configuring the underlying select
Since we hide the underlying `MatSelect` inside the `MatPaginator`, the user doesn't have the ability to configure some of the inputs. These changes introduce an input that proxy some of the supported properties to the select. Fixes #13646.
1 parent 14cdd89 commit 191d116

File tree

5 files changed

+55
-4
lines changed

5 files changed

+55
-4
lines changed

src/material/paginator/paginator.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
<mat-select
1313
[value]="pageSize"
1414
[disabled]="disabled"
15+
[panelClass]="selectConfig.panelClass"
16+
[disableOptionCentering]="selectConfig.disableOptionCentering"
1517
[aria-label]="_intl.itemsPerPageLabel"
1618
(selectionChange)="_changePageSize($event.value)">
17-
<mat-option *ngFor="let pageSizeOption of _displayedPageSizeOptions" [value]="pageSizeOption">
19+
<mat-option *ngFor="let pageSizeOption of _displayedPageSizeOptions"
20+
[value]="pageSizeOption">
1821
{{pageSizeOption}}
1922
</mat-option>
2023
</mat-select>

src/material/paginator/paginator.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ any associated data view.
1616
The paginator displays a dropdown of page sizes for the user to choose from. The options for this
1717
dropdown can be set via `pageSizeOptions`
1818

19-
The current pageSize will always appear in the dropdown, even if it is not included in pageSizeOptions.
19+
The current pageSize will always appear in the dropdown, even if it is not included in
20+
pageSizeOptions.
21+
22+
If you want to customize some of the optional of the `mat-select` inside the `mat-paginator`, you
23+
can use the `selectConfig` input.
2024

2125
### Internationalization
2226
The labels for the paginator can be customized by providing your own instance of `MatPaginatorIntl`.
@@ -26,4 +30,5 @@ This will allow you to change the following:
2630
3. The tooltip messages on the navigation buttons.
2731

2832
### Accessibility
29-
The `aria-label`s for next page, previous page, first page and last page buttons can be set in `MatPaginatorIntl`.
33+
The `aria-label`s for next page, previous page, first page and last page buttons can be set in
34+
`MatPaginatorIntl`.

src/material/paginator/paginator.spec.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import {dispatchMouseEvent} from '@angular/cdk/testing';
55
import {ThemePalette} from '@angular/material/core';
66
import {MatSelect} from '@angular/material/select';
77
import {By} from '@angular/platform-browser';
8-
import {MatPaginatorModule, MatPaginator, MatPaginatorIntl} from './index';
8+
import {
9+
MatPaginatorModule,
10+
MatPaginator,
11+
MatPaginatorIntl,
12+
MatPaginatorSelectConfig,
13+
} from './index';
914

1015

1116
describe('MatPaginator', () => {
@@ -180,6 +185,22 @@ describe('MatPaginator', () => {
180185
expect(formField.classList).toContain('mat-accent');
181186
});
182187

188+
it('should be able to pass options to the underlying mat-select', () => {
189+
const select: MatSelect = fixture.debugElement.query(By.directive(MatSelect)).componentInstance;
190+
191+
expect(select.disableOptionCentering).toBe(false);
192+
expect(select.panelClass).toBeFalsy();
193+
194+
fixture.componentInstance.selectConfig = {
195+
disableOptionCentering: true,
196+
panelClass: 'custom-class'
197+
};
198+
fixture.detectChanges();
199+
200+
expect(select.disableOptionCentering).toBe(true);
201+
expect(select.panelClass).toBe('custom-class');
202+
});
203+
183204
describe('when showing the first and last button', () => {
184205

185206
beforeEach(() => {
@@ -438,6 +459,7 @@ function getLastButton(fixture: ComponentFixture<any>) {
438459
[pageSize]="pageSize"
439460
[pageSizeOptions]="pageSizeOptions"
440461
[hidePageSize]="hidePageSize"
462+
[selectConfig]="selectConfig"
441463
[showFirstLastButtons]="showFirstLastButtons"
442464
[length]="length"
443465
[color]="color"
@@ -456,6 +478,7 @@ class MatPaginatorApp {
456478
disabled: boolean;
457479
pageEvent = jasmine.createSpy('page event');
458480
color: ThemePalette;
481+
selectConfig: MatPaginatorSelectConfig = {};
459482

460483
@ViewChild(MatPaginator, {static: false}) paginator: MatPaginator;
461484

src/material/paginator/paginator.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ export class PageEvent {
5454
length: number;
5555
}
5656

57+
/** Object that can used to configure the underlying `MatSelect` inside a `MatPaginator`. */
58+
export interface MatPaginatorSelectConfig {
59+
/** Whether to center the active option over the trigger. */
60+
disableOptionCentering?: boolean;
61+
62+
/** Classes to be passed to the select panel. */
63+
panelClass?: string|string[]|Set<string>|{[key: string]: any};
64+
}
65+
5766
// Boilerplate for applying mixins to MatPaginator.
5867
/** @docs-private */
5968
class MatPaginatorBase {}
@@ -139,6 +148,9 @@ export class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy
139148
}
140149
private _showFirstLastButtons = false;
141150

151+
/** Used to configure the underlying `MatSelect` inside the paginator. */
152+
@Input() selectConfig: MatPaginatorSelectConfig = {};
153+
142154
/** Event emitted when the paginator changes the page size or page index. */
143155
@Output() readonly page: EventEmitter<PageEvent> = new EventEmitter<PageEvent>();
144156

tools/public_api_guard/material/paginator.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export declare class MatPaginator extends _MatPaginatorBase implements OnInit, O
1616
pageIndex: number;
1717
pageSize: number;
1818
pageSizeOptions: number[];
19+
selectConfig: MatPaginatorSelectConfig;
1920
showFirstLastButtons: boolean;
2021
constructor(_intl: MatPaginatorIntl, _changeDetectorRef: ChangeDetectorRef);
2122
_changePageSize(pageSize: number): void;
@@ -45,6 +46,13 @@ export declare class MatPaginatorIntl {
4546
export declare class MatPaginatorModule {
4647
}
4748

49+
export interface MatPaginatorSelectConfig {
50+
disableOptionCentering?: boolean;
51+
panelClass?: string | string[] | Set<string> | {
52+
[key: string]: any;
53+
};
54+
}
55+
4856
export declare class PageEvent {
4957
length: number;
5058
pageIndex: number;

0 commit comments

Comments
 (0)