Skip to content

feat(mat-paginator): Optionally style the mat-paginator form-field #18800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/material/paginator/paginator.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<mat-form-field
*ngIf="_displayedPageSizeOptions.length > 1"
[appearance]="_formFieldAppearance"
[color]="color"
class="mat-paginator-page-size-select">
<mat-select
Expand Down
19 changes: 18 additions & 1 deletion src/material/paginator/paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
CanDisableCtor,
CanDisable,
} from '@angular/material/core';
import {MatFormFieldAppearance} from '@angular/material/form-field';

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

/** Whether to show the first/last buttons UI to the user. */
showFirstLastButtons?: boolean;

/** The default form-field appearance to apply to the page size options selector. */
formFieldAppearance?: MatFormFieldAppearance;
}

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

/** If set, styles the "page size" form field with the designated style. */
_formFieldAppearance?: MatFormFieldAppearance;

constructor(public _intl: MatPaginatorIntl,
private _changeDetectorRef: ChangeDetectorRef,
@Optional() @Inject(MAT_PAGINATOR_DEFAULT_OPTIONS)
Expand All @@ -180,7 +187,13 @@ export class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy
this._intlChanges = _intl.changes.subscribe(() => this._changeDetectorRef.markForCheck());

if (defaults) {
const {pageSize, pageSizeOptions, hidePageSize, showFirstLastButtons} = defaults;
const {
pageSize,
pageSizeOptions,
hidePageSize,
showFirstLastButtons,
formFieldAppearance,
} = defaults;

if (pageSize != null) {
this._pageSize = pageSize;
Expand All @@ -197,6 +210,10 @@ export class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy
if (showFirstLastButtons != null) {
this._showFirstLastButtons = showFirstLastButtons;
}

if (formFieldAppearance != null) {
this._formFieldAppearance = formFieldAppearance;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions tools/public_api_guard/material/paginator.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export declare function MAT_PAGINATOR_INTL_PROVIDER_FACTORY(parentIntl: MatPagin

export declare class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy, CanDisable, HasInitialized {
_displayedPageSizeOptions: number[];
_formFieldAppearance?: MatFormFieldAppearance;
_intl: MatPaginatorIntl;
color: ThemePalette;
get hidePageSize(): boolean;
Expand Down Expand Up @@ -49,6 +50,7 @@ export declare class MatPaginator extends _MatPaginatorBase implements OnInit, O
}

export interface MatPaginatorDefaultOptions {
formFieldAppearance?: MatFormFieldAppearance;
hidePageSize?: boolean;
pageSize?: number;
pageSizeOptions?: number[];
Expand Down