Skip to content

Commit bcc98fb

Browse files
committed
feat(material/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 0dfc490 commit bcc98fb

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

src/material-experimental/mdc-paginator/paginator.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
[value]="pageSize"
1515
[disabled]="disabled"
1616
[aria-labelledby]="_pageSizeLabelId"
17+
[panelClass]="selectConfig.panelClass || ''"
18+
[disableOptionCentering]="selectConfig.disableOptionCentering"
1719
(selectionChange)="_changePageSize($event.value)">
1820
<mat-option *ngFor="let pageSizeOption of _displayedPageSizeOptions" [value]="pageSizeOption">
1921
{{pageSizeOption}}

src/material-experimental/mdc-paginator/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export {
1313
MAT_PAGINATOR_INTL_PROVIDER_FACTORY,
1414
MAT_PAGINATOR_INTL_PROVIDER,
1515
PageEvent,
16+
MatPaginatorSelectConfig,
1617
} from '@angular/material/paginator';

src/material/paginator/paginator.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<mat-select
1414
[value]="pageSize"
1515
[disabled]="disabled"
16+
[panelClass]="selectConfig.panelClass || ''"
17+
[disableOptionCentering]="selectConfig.disableOptionCentering"
1618
[aria-label]="_intl.itemsPerPageLabel"
1719
(selectionChange)="_changePageSize($event.value)">
1820
<mat-option *ngFor="let pageSizeOption of _displayedPageSizeOptions" [value]="pageSizeOption">

src/material/paginator/paginator.md

Lines changed: 6 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`.
@@ -30,5 +34,5 @@ The paginator uses `role="group"` to semantically group its child controls. You
3034
`aria-label` or `aria-labelledby` attribute to `<mat-paginator>` with a label that describes
3135
the content controlled by the pagination control.
3236

33-
You can set the `aria-label` attributes for the button and select controls within the paginator in
37+
You can set the `aria-label` attributes for the button and select controls within the paginator in
3438
`MatPaginatorIntl`.

src/material/paginator/paginator.spec.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import {ThemePalette} from '@angular/material/core';
66
import {MatSelect} from '@angular/material/select';
77
import {By} from '@angular/platform-browser';
88
import {MatPaginator, MatPaginatorIntl, MatPaginatorModule} from './index';
9-
import {MAT_PAGINATOR_DEFAULT_OPTIONS, MatPaginatorDefaultOptions} from './paginator';
9+
import {
10+
MAT_PAGINATOR_DEFAULT_OPTIONS,
11+
MatPaginatorDefaultOptions,
12+
MatPaginatorSelectConfig,
13+
} from './paginator';
1014

1115
describe('MatPaginator', () => {
1216
function createComponent<T>(type: Type<T>, providers: Provider[] = []): ComponentFixture<T> {
@@ -210,6 +214,24 @@ describe('MatPaginator', () => {
210214
expect(formField.classList).not.toContain('mat-accent');
211215
});
212216

217+
it('should be able to pass options to the underlying mat-select', () => {
218+
const fixture = createComponent(MatPaginatorApp);
219+
fixture.detectChanges();
220+
const select: MatSelect = fixture.debugElement.query(By.directive(MatSelect)).componentInstance;
221+
222+
expect(select.disableOptionCentering).toBe(false);
223+
expect(select.panelClass).toBeFalsy();
224+
225+
fixture.componentInstance.selectConfig = {
226+
disableOptionCentering: true,
227+
panelClass: 'custom-class',
228+
};
229+
fixture.detectChanges();
230+
231+
expect(select.disableOptionCentering).toBe(true);
232+
expect(select.panelClass).toBe('custom-class');
233+
});
234+
213235
describe('when showing the first and last button', () => {
214236
let fixture: ComponentFixture<MatPaginatorApp>;
215237
let component: MatPaginatorApp;
@@ -537,6 +559,7 @@ function getLastButton(fixture: ComponentFixture<any>) {
537559
[pageSize]="pageSize"
538560
[pageSizeOptions]="pageSizeOptions"
539561
[hidePageSize]="hidePageSize"
562+
[selectConfig]="selectConfig"
540563
[showFirstLastButtons]="showFirstLastButtons"
541564
[length]="length"
542565
[color]="color"
@@ -555,6 +578,7 @@ class MatPaginatorApp {
555578
disabled: boolean;
556579
pageEvent = jasmine.createSpy('page event');
557580
color: ThemePalette;
581+
selectConfig: MatPaginatorSelectConfig = {};
558582

559583
@ViewChild(MatPaginator) paginator: MatPaginator;
560584

src/material/paginator/paginator.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ export const MAT_PAGINATOR_DEFAULT_OPTIONS = new InjectionToken<MatPaginatorDefa
8989
/** @docs-private */
9090
const _MatPaginatorMixinBase = mixinDisabled(mixinInitialized(class {}));
9191

92+
/** Object that can used to configure the underlying `MatSelect` inside a `MatPaginator`. */
93+
export interface MatPaginatorSelectConfig {
94+
/** Whether to center the active option over the trigger. */
95+
disableOptionCentering?: boolean;
96+
97+
/** Classes to be passed to the select panel. */
98+
panelClass?: string | string[] | Set<string> | {[key: string]: any};
99+
}
100+
92101
/**
93102
* Base class with all of the `MatPaginator` functionality.
94103
* @docs-private
@@ -175,6 +184,9 @@ export abstract class _MatPaginatorBase<
175184
}
176185
private _showFirstLastButtons = false;
177186

187+
/** Used to configure the underlying `MatSelect` inside the paginator. */
188+
@Input() selectConfig: MatPaginatorSelectConfig = {};
189+
178190
/** Event emitted when the paginator changes the page size or page index. */
179191
@Output() readonly page: EventEmitter<PageEvent> = new EventEmitter<PageEvent>();
180192

0 commit comments

Comments
 (0)