Skip to content

Commit 36e0b22

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 efeefd1 commit 36e0b22

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

src/lib/paginator/paginator.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
class="mat-paginator-page-size-select">
1212
<mat-select
1313
[value]="pageSize"
14+
[panelClass]="selectConfig.panelClass"
15+
[disableOptionCentering]="selectConfig.disableOptionCentering"
1416
[aria-label]="_intl.itemsPerPageLabel"
1517
(selectionChange)="_changePageSize($event.value)">
16-
<mat-option *ngFor="let pageSizeOption of _displayedPageSizeOptions" [value]="pageSizeOption">
18+
<mat-option *ngFor="let pageSizeOption of _displayedPageSizeOptions"
19+
[value]="pageSizeOption">
1720
{{pageSizeOption}}
1821
</mat-option>
1922
</mat-select>

src/lib/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/lib/paginator/paginator.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import {async, ComponentFixture, TestBed, inject, tick, fakeAsync} from '@angular/core/testing';
22
import {MatPaginatorModule} from './index';
3-
import {MatPaginator} from './paginator';
3+
import {MatPaginator, MatPaginatorSelectConfig} from './paginator';
44
import {Component, ViewChild} from '@angular/core';
55
import {MatPaginatorIntl} from './paginator-intl';
66
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
77
import {dispatchMouseEvent} from '@angular/cdk/testing';
88
import {ThemePalette} from '@angular/material/core';
9+
import {By} from '@angular/platform-browser';
10+
import {MatSelect} from '@angular/material/select';
911

1012

1113
describe('MatPaginator', () => {
@@ -180,6 +182,22 @@ describe('MatPaginator', () => {
180182
expect(formField.classList).toContain('mat-accent');
181183
});
182184

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

185203
beforeEach(() => {
@@ -415,6 +433,7 @@ function getLastButton(fixture: ComponentFixture<any>) {
415433
[pageSize]="pageSize"
416434
[pageSizeOptions]="pageSizeOptions"
417435
[hidePageSize]="hidePageSize"
436+
[selectConfig]="selectConfig"
418437
[showFirstLastButtons]="showFirstLastButtons"
419438
[length]="length"
420439
[color]="color"
@@ -431,6 +450,7 @@ class MatPaginatorApp {
431450
length = 100;
432451
pageEvent = jasmine.createSpy('page event');
433452
color: ThemePalette;
453+
selectConfig: MatPaginatorSelectConfig = {};
434454

435455
@ViewChild(MatPaginator) paginator: MatPaginator;
436456

src/lib/paginator/paginator.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ export class PageEvent {
5151
length: number;
5252
}
5353

54+
/** Object that can used to configure the underlying `MatSelect` inside a `MatPaginator`. */
55+
export interface MatPaginatorSelectConfig {
56+
/** Whether to center the active option over the trigger. */
57+
disableOptionCentering?: boolean;
58+
59+
/** Classes to be passed to the select panel. */
60+
panelClass?: string|string[]|Set<string>|{[key: string]: any};
61+
}
62+
5463
// Boilerplate for applying mixins to MatPaginator.
5564
/** @docs-private */
5665
export class MatPaginatorBase {}
@@ -134,6 +143,9 @@ export class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy
134143
}
135144
private _showFirstLastButtons = false;
136145

146+
/** Used to configure the underlying `MatSelect` inside the paginator. */
147+
@Input() selectConfig: MatPaginatorSelectConfig = {};
148+
137149
/** Event emitted when the paginator changes the page size or page index. */
138150
@Output() readonly page: EventEmitter<PageEvent> = new EventEmitter<PageEvent>();
139151

0 commit comments

Comments
 (0)