Skip to content

Commit 93057aa

Browse files
lekhmanrusamysorto
authored andcommitted
feat(material/progress-spinner): add color to default options (angular#24356)
closes angular#24352
1 parent 87f5292 commit 93057aa

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

src/material-experimental/mdc-progress-spinner/progress-spinner.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,28 @@ describe('MDC-based MatProgressSpinner', () => {
340340
expect(progressElement.componentInstance.strokeWidth).toBe(7);
341341
});
342342

343+
it('should be able to set a default color', () => {
344+
TestBed.resetTestingModule()
345+
.configureTestingModule({
346+
imports: [MatProgressSpinnerModule],
347+
declarations: [BasicProgressSpinner],
348+
providers: [
349+
{
350+
provide: MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS,
351+
useValue: {color: 'warn'},
352+
},
353+
],
354+
})
355+
.compileComponents();
356+
357+
const fixture = TestBed.createComponent(BasicProgressSpinner);
358+
fixture.detectChanges();
359+
360+
const progressElement = fixture.debugElement.query(By.css('mat-progress-spinner'))!;
361+
expect(progressElement.componentInstance.color).toBe('warn');
362+
expect(progressElement.nativeElement.classList).toContain('mat-warn');
363+
});
364+
343365
it('should set `aria-valuenow` to the current value in determinate mode', () => {
344366
const fixture = TestBed.createComponent(ProgressSpinnerWithValueAndBoundMode);
345367
const progressElement = fixture.debugElement.query(By.css('mat-progress-spinner'))!;

src/material-experimental/mdc-progress-spinner/progress-spinner.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ export class MatProgressSpinner
120120
animationMode === 'NoopAnimations' && !!defaults && !defaults._forceAnimations;
121121

122122
if (defaults) {
123+
if (defaults.color) {
124+
this.color = this.defaultColor = defaults.color;
125+
}
126+
123127
if (defaults.diameter) {
124128
this.diameter = defaults.diameter;
125129
}

src/material/progress-spinner/progress-spinner.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,28 @@ describe('MatProgressSpinner', () => {
407407
expect(progressElement.componentInstance.strokeWidth).toBe(7);
408408
});
409409

410+
it('should be able to set a default color', () => {
411+
TestBed.resetTestingModule()
412+
.configureTestingModule({
413+
imports: [MatProgressSpinnerModule],
414+
declarations: [BasicProgressSpinner],
415+
providers: [
416+
{
417+
provide: MAT_PROGRESS_SPINNER_DEFAULT_OPTIONS,
418+
useValue: {color: 'warn'},
419+
},
420+
],
421+
})
422+
.compileComponents();
423+
424+
const fixture = TestBed.createComponent(BasicProgressSpinner);
425+
fixture.detectChanges();
426+
427+
const progressElement = fixture.debugElement.query(By.css('mat-progress-spinner'))!;
428+
expect(progressElement.componentInstance.color).toBe('warn');
429+
expect(progressElement.nativeElement.classList).toContain('mat-warn');
430+
});
431+
410432
it('should set `aria-valuenow` to the current value in determinate mode', () => {
411433
const fixture = TestBed.createComponent(ProgressSpinnerWithValueAndBoundMode);
412434
const progressElement = fixture.debugElement.query(By.css('mat-progress-spinner'))!;

src/material/progress-spinner/progress-spinner.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
OnDestroy,
2525
NgZone,
2626
} from '@angular/core';
27-
import {CanColor, mixinColor} from '@angular/material/core';
27+
import {CanColor, mixinColor, ThemePalette} from '@angular/material/core';
2828
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
2929
import {Subscription} from 'rxjs';
3030

@@ -54,6 +54,8 @@ const _MatProgressSpinnerBase = mixinColor(
5454

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

230232
if (defaults) {
233+
if (defaults.color) {
234+
this.color = this.defaultColor = defaults.color;
235+
}
236+
231237
if (defaults.diameter) {
232238
this.diameter = defaults.diameter;
233239
}

tools/public_api_guard/material/progress-spinner.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { NumberInput } from '@angular/cdk/coercion';
1818
import { OnDestroy } from '@angular/core';
1919
import { OnInit } from '@angular/core';
2020
import { Platform } from '@angular/cdk/platform';
21+
import { ThemePalette } from '@angular/material/core';
2122
import { ViewportRuler } from '@angular/cdk/scrolling';
2223

2324
// @public
@@ -57,6 +58,7 @@ export class MatProgressSpinner extends _MatProgressSpinnerBase implements OnIni
5758

5859
// @public
5960
export interface MatProgressSpinnerDefaultOptions {
61+
color?: ThemePalette;
6062
diameter?: number;
6163
_forceAnimations?: boolean;
6264
strokeWidth?: number;

0 commit comments

Comments
 (0)