Skip to content

Commit f9c6d2a

Browse files
authored
feat(mat-paginator): Optionally style the mat-paginator form-field (#18800)
Adds a new option to the MatPaginatorDefaultOptions that allows users to set the appearance of the page size form field in mat-paginator.
1 parent 23818f5 commit f9c6d2a

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/material/paginator/paginator.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<mat-form-field
99
*ngIf="_displayedPageSizeOptions.length > 1"
10+
[appearance]="_formFieldAppearance"
1011
[color]="color"
1112
class="mat-paginator-page-size-select">
1213
<mat-select

src/material/paginator/paginator.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
CanDisableCtor,
3838
CanDisable,
3939
} from '@angular/material/core';
40+
import {MatFormFieldAppearance} from '@angular/material/form-field';
4041

4142
/** The default page size if there is no page size and there are no provided page size options. */
4243
const DEFAULT_PAGE_SIZE = 50;
@@ -76,6 +77,9 @@ export interface MatPaginatorDefaultOptions {
7677

7778
/** Whether to show the first/last buttons UI to the user. */
7879
showFirstLastButtons?: boolean;
80+
81+
/** The default form-field appearance to apply to the page size options selector. */
82+
formFieldAppearance?: MatFormFieldAppearance;
7983
}
8084

8185
/** Injection token that can be used to provide the default options for the paginator module. */
@@ -172,6 +176,9 @@ export class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy
172176
/** Displayed set of page size options. Will be sorted and include current page size. */
173177
_displayedPageSizeOptions: number[];
174178

179+
/** If set, styles the "page size" form field with the designated style. */
180+
_formFieldAppearance?: MatFormFieldAppearance;
181+
175182
constructor(public _intl: MatPaginatorIntl,
176183
private _changeDetectorRef: ChangeDetectorRef,
177184
@Optional() @Inject(MAT_PAGINATOR_DEFAULT_OPTIONS)
@@ -180,7 +187,13 @@ export class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy
180187
this._intlChanges = _intl.changes.subscribe(() => this._changeDetectorRef.markForCheck());
181188

182189
if (defaults) {
183-
const {pageSize, pageSizeOptions, hidePageSize, showFirstLastButtons} = defaults;
190+
const {
191+
pageSize,
192+
pageSizeOptions,
193+
hidePageSize,
194+
showFirstLastButtons,
195+
formFieldAppearance,
196+
} = defaults;
184197

185198
if (pageSize != null) {
186199
this._pageSize = pageSize;
@@ -197,6 +210,10 @@ export class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy
197210
if (showFirstLastButtons != null) {
198211
this._showFirstLastButtons = showFirstLastButtons;
199212
}
213+
214+
if (formFieldAppearance != null) {
215+
this._formFieldAppearance = formFieldAppearance;
216+
}
200217
}
201218
}
202219

tools/public_api_guard/material/paginator.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export declare function MAT_PAGINATOR_INTL_PROVIDER_FACTORY(parentIntl: MatPagin
1010

1111
export declare class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy, CanDisable, HasInitialized {
1212
_displayedPageSizeOptions: number[];
13+
_formFieldAppearance?: MatFormFieldAppearance;
1314
_intl: MatPaginatorIntl;
1415
color: ThemePalette;
1516
get hidePageSize(): boolean;
@@ -49,6 +50,7 @@ export declare class MatPaginator extends _MatPaginatorBase implements OnInit, O
4950
}
5051

5152
export interface MatPaginatorDefaultOptions {
53+
formFieldAppearance?: MatFormFieldAppearance;
5254
hidePageSize?: boolean;
5355
pageSize?: number;
5456
pageSizeOptions?: number[];

0 commit comments

Comments
 (0)