Skip to content

Commit e18a99f

Browse files
crisbetojelbourn
authored andcommitted
feat(paginator): allow form field color to be customized (#12834)
Adds a `color` input on the paginator that allows for the color to be set on the underlying components that are hidden away from the consumer.
1 parent f6e787a commit e18a99f

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/lib/paginator/paginator.html

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

77
<mat-form-field
88
*ngIf="_displayedPageSizeOptions.length > 1"
9+
[color]="color"
910
class="mat-paginator-page-size-select">
1011
<mat-select
1112
[value]="pageSize"

src/lib/paginator/paginator.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ 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';
8+
import {ThemePalette} from '@angular/material/core';
89

910

1011
describe('MatPaginator', () => {
@@ -167,6 +168,18 @@ describe('MatPaginator', () => {
167168
expect(paginator.pageIndex).toBeGreaterThanOrEqual(0);
168169
});
169170

171+
it('should be able to set the color of the form field', () => {
172+
const formField: HTMLElement = fixture.nativeElement.querySelector('.mat-form-field');
173+
174+
expect(formField.classList).toContain('mat-primary');
175+
176+
component.color = 'accent';
177+
fixture.detectChanges();
178+
179+
expect(formField.classList).not.toContain('mat-primary');
180+
expect(formField.classList).toContain('mat-accent');
181+
});
182+
170183
describe('when showing the first and last button', () => {
171184

172185
beforeEach(() => {
@@ -387,6 +400,7 @@ function getLastButton(fixture: ComponentFixture<any>) {
387400
[hidePageSize]="hidePageSize"
388401
[showFirstLastButtons]="showFirstLastButtons"
389402
[length]="length"
403+
[color]="color"
390404
(page)="pageEvent($event)">
391405
</mat-paginator>
392406
`,
@@ -399,6 +413,7 @@ class MatPaginatorApp {
399413
showFirstLastButtons = false;
400414
length = 100;
401415
pageEvent = jasmine.createSpy('page event');
416+
color: ThemePalette;
402417

403418
@ViewChild(MatPaginator) paginator: MatPaginator;
404419

src/lib/paginator/paginator.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
} from '@angular/core';
2121
import {Subscription} from 'rxjs';
2222
import {MatPaginatorIntl} from './paginator-intl';
23-
import {HasInitialized, mixinInitialized} from '@angular/material/core';
23+
import {HasInitialized, mixinInitialized, ThemePalette} from '@angular/material/core';
2424

2525
/** The default page size if there is no page size and there are no provided page size options. */
2626
const DEFAULT_PAGE_SIZE = 50;
@@ -72,6 +72,9 @@ export class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy
7272
private _initialized: boolean;
7373
private _intlChanges: Subscription;
7474

75+
/** Theme color to be used for the underlying form controls. */
76+
@Input() color: ThemePalette;
77+
7578
/** The zero-based page index of the displayed list of items. Defaulted to 0. */
7679
@Input()
7780
get pageIndex(): number { return this._pageIndex; }

0 commit comments

Comments
 (0)