Skip to content

Commit

Permalink
feat(paginator): allow form field color to be customized (#12834)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crisbeto authored and jelbourn committed Aug 27, 2018
1 parent f6e787a commit e18a99f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lib/paginator/paginator.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<mat-form-field
*ngIf="_displayedPageSizeOptions.length > 1"
[color]="color"
class="mat-paginator-page-size-select">
<mat-select
[value]="pageSize"
Expand Down
15 changes: 15 additions & 0 deletions src/lib/paginator/paginator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Component, ViewChild} from '@angular/core';
import {MatPaginatorIntl} from './paginator-intl';
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
import {dispatchMouseEvent} from '@angular/cdk/testing';
import {ThemePalette} from '@angular/material/core';


describe('MatPaginator', () => {
Expand Down Expand Up @@ -167,6 +168,18 @@ describe('MatPaginator', () => {
expect(paginator.pageIndex).toBeGreaterThanOrEqual(0);
});

it('should be able to set the color of the form field', () => {
const formField: HTMLElement = fixture.nativeElement.querySelector('.mat-form-field');

expect(formField.classList).toContain('mat-primary');

component.color = 'accent';
fixture.detectChanges();

expect(formField.classList).not.toContain('mat-primary');
expect(formField.classList).toContain('mat-accent');
});

describe('when showing the first and last button', () => {

beforeEach(() => {
Expand Down Expand Up @@ -387,6 +400,7 @@ function getLastButton(fixture: ComponentFixture<any>) {
[hidePageSize]="hidePageSize"
[showFirstLastButtons]="showFirstLastButtons"
[length]="length"
[color]="color"
(page)="pageEvent($event)">
</mat-paginator>
`,
Expand All @@ -399,6 +413,7 @@ class MatPaginatorApp {
showFirstLastButtons = false;
length = 100;
pageEvent = jasmine.createSpy('page event');
color: ThemePalette;

@ViewChild(MatPaginator) paginator: MatPaginator;

Expand Down
5 changes: 4 additions & 1 deletion src/lib/paginator/paginator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '@angular/core';
import {Subscription} from 'rxjs';
import {MatPaginatorIntl} from './paginator-intl';
import {HasInitialized, mixinInitialized} from '@angular/material/core';
import {HasInitialized, mixinInitialized, ThemePalette} from '@angular/material/core';

/** 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 @@ -72,6 +72,9 @@ export class MatPaginator extends _MatPaginatorBase implements OnInit, OnDestroy
private _initialized: boolean;
private _intlChanges: Subscription;

/** Theme color to be used for the underlying form controls. */
@Input() color: ThemePalette;

/** The zero-based page index of the displayed list of items. Defaulted to 0. */
@Input()
get pageIndex(): number { return this._pageIndex; }
Expand Down

0 comments on commit e18a99f

Please sign in to comment.