Skip to content

Commit 9392223

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 5b3e846 commit 9392223

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-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(() => {
@@ -437,6 +458,7 @@ function getLastButton(fixture: ComponentFixture<any>) {
437458
[pageSize]="pageSize"
438459
[pageSizeOptions]="pageSizeOptions"
439460
[hidePageSize]="hidePageSize"
461+
[selectConfig]="selectConfig"
440462
[showFirstLastButtons]="showFirstLastButtons"
441463
[length]="length"
442464
[color]="color"
@@ -455,6 +477,7 @@ class MatPaginatorApp {
455477
disabled: boolean;
456478
pageEvent = jasmine.createSpy('page event');
457479
color: ThemePalette;
480+
selectConfig: MatPaginatorSelectConfig = {};
458481

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

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

0 commit comments

Comments
 (0)