Skip to content

Commit

Permalink
feat(material/progress-spinner): add color to default options (#24356)
Browse files Browse the repository at this point in the history
closes #24352
  • Loading branch information
lekhmanrus committed Feb 11, 2022
1 parent 68e7bd0 commit ca1aaae
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,28 @@ describe('MDC-based MatProgressSpinner', () => {
expect(progressElement.componentInstance.strokeWidth).toBe(7);
});

it('should be able to set a default color', () => {
TestBed.resetTestingModule()
.configureTestingModule({
imports: [MatProgressSpinnerModule],
declarations: [BasicProgressSpinner],
providers: [
{
provide: MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS,
useValue: {color: 'warn'},
},
],
})
.compileComponents();

const fixture = TestBed.createComponent(BasicProgressSpinner);
fixture.detectChanges();

const progressElement = fixture.debugElement.query(By.css('mat-progress-spinner'))!;
expect(progressElement.componentInstance.color).toBe('warn');
expect(progressElement.nativeElement.classList).toContain('mat-warn');
});

it('should set `aria-valuenow` to the current value in determinate mode', () => {
const fixture = TestBed.createComponent(ProgressSpinnerWithValueAndBoundMode);
const progressElement = fixture.debugElement.query(By.css('mat-progress-spinner'))!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export class MatProgressSpinner
animationMode === 'NoopAnimations' && !!defaults && !defaults._forceAnimations;

if (defaults) {
if (defaults.color) {
this.color = this.defaultColor = defaults.color;
}

if (defaults.diameter) {
this.diameter = defaults.diameter;
}
Expand Down
22 changes: 22 additions & 0 deletions src/material/progress-spinner/progress-spinner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,28 @@ describe('MatProgressSpinner', () => {
expect(progressElement.componentInstance.strokeWidth).toBe(7);
});

it('should be able to set a default color', () => {
TestBed.resetTestingModule()
.configureTestingModule({
imports: [MatProgressSpinnerModule],
declarations: [BasicProgressSpinner],
providers: [
{
provide: MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS,
useValue: {color: 'warn'},
},
],
})
.compileComponents();

const fixture = TestBed.createComponent(BasicProgressSpinner);
fixture.detectChanges();

const progressElement = fixture.debugElement.query(By.css('mat-progress-spinner'))!;
expect(progressElement.componentInstance.color).toBe('warn');
expect(progressElement.nativeElement.classList).toContain('mat-warn');
});

it('should set `aria-valuenow` to the current value in determinate mode', () => {
const fixture = TestBed.createComponent(ProgressSpinnerWithValueAndBoundMode);
const progressElement = fixture.debugElement.query(By.css('mat-progress-spinner'))!;
Expand Down
8 changes: 7 additions & 1 deletion src/material/progress-spinner/progress-spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
OnDestroy,
NgZone,
} from '@angular/core';
import {CanColor, mixinColor} from '@angular/material/core';
import {CanColor, mixinColor, ThemePalette} from '@angular/material/core';
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
import {Subscription} from 'rxjs';

Expand Down Expand Up @@ -54,6 +54,8 @@ const _MatProgressSpinnerBase = mixinColor(

/** Default `mat-progress-spinner` options that can be overridden. */
export interface MatProgressSpinnerDefaultOptions {
/** Default color of the spinner. */
color?: ThemePalette;
/** Diameter of the spinner. */
diameter?: number;
/** Width of the spinner's stroke. */
Expand Down Expand Up @@ -228,6 +230,10 @@ export class MatProgressSpinner
animationMode === 'NoopAnimations' && !!defaults && !defaults._forceAnimations;

if (defaults) {
if (defaults.color) {
this.color = this.defaultColor = defaults.color;
}

if (defaults.diameter) {
this.diameter = defaults.diameter;
}
Expand Down
2 changes: 2 additions & 0 deletions tools/public_api_guard/material/progress-spinner.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { NumberInput } from '@angular/cdk/coercion';
import { OnDestroy } from '@angular/core';
import { OnInit } from '@angular/core';
import { Platform } from '@angular/cdk/platform';
import { ThemePalette } from '@angular/material/core';
import { ViewportRuler } from '@angular/cdk/scrolling';

// @public
Expand Down Expand Up @@ -57,6 +58,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerBase implements OnIni

// @public
export interface MatProgressSpinnerDefaultOptions {
color?: ThemePalette;
diameter?: number;
_forceAnimations?: boolean;
strokeWidth?: number;
Expand Down

0 comments on commit ca1aaae

Please sign in to comment.