Skip to content

Commit ef1ae05

Browse files
crisbetoangular-robot[bot]
authored andcommitted
fix(material/legacy-progress-spinner): avoid CSP errors
Uses the new `CSP_NONCE` injection token to avoid errors when inserting a `style` tag dynamically for the spinner animation.
1 parent e78d058 commit ef1ae05

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
ChangeDetectorRef,
2323
OnDestroy,
2424
NgZone,
25+
CSP_NONCE,
2526
} from '@angular/core';
2627
import {CanColor, mixinColor} from '@angular/material/core';
2728
import {ANIMATION_MODULE_TYPE} from '@angular/platform-browser/animations';
@@ -191,6 +192,7 @@ export class MatLegacyProgressSpinner
191192
changeDetectorRef?: ChangeDetectorRef,
192193
viewportRuler?: ViewportRuler,
193194
ngZone?: NgZone,
195+
@Inject(CSP_NONCE) @Optional() private _nonce?: string | null,
194196
) {
195197
super(elementRef);
196198

@@ -305,6 +307,11 @@ export class MatLegacyProgressSpinner
305307

306308
if (!diametersForElement || !diametersForElement.has(currentDiameter)) {
307309
const styleTag: HTMLStyleElement = this._document.createElement('style');
310+
311+
if (this._nonce) {
312+
styleTag.nonce = this._nonce;
313+
}
314+
308315
styleTag.setAttribute('mat-spinner-animation', this._spinnerAnimationLabel);
309316
styleTag.textContent = this._getAnimationText();
310317
styleRoot.appendChild(styleTag);

tools/public_api_guard/material/legacy-progress-spinner.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export { MAT_LEGACY_PROGRESS_SPINNER_DEFAULT_OPTIONS_FACTORY }
3232
// @public @deprecated
3333
export class MatLegacyProgressSpinner extends _MatProgressSpinnerBase implements OnInit, OnDestroy, CanColor {
3434
constructor(elementRef: ElementRef<HTMLElement>, _platform: Platform, _document: any, animationMode: string, defaults?: MatLegacyProgressSpinnerDefaultOptions,
35-
changeDetectorRef?: ChangeDetectorRef, viewportRuler?: ViewportRuler, ngZone?: NgZone);
35+
changeDetectorRef?: ChangeDetectorRef, viewportRuler?: ViewportRuler, ngZone?: NgZone, _nonce?: string | null | undefined);
3636
get diameter(): number;
3737
set diameter(size: NumberInput);
3838
_getCircleRadius(): number;
@@ -55,7 +55,7 @@ export class MatLegacyProgressSpinner extends _MatProgressSpinnerBase implements
5555
// (undocumented)
5656
static ɵcmp: i0.ɵɵComponentDeclaration<MatLegacyProgressSpinner, "mat-progress-spinner, mat-spinner", ["matProgressSpinner"], { "color": { "alias": "color"; "required": false; }; "diameter": { "alias": "diameter"; "required": false; }; "strokeWidth": { "alias": "strokeWidth"; "required": false; }; "mode": { "alias": "mode"; "required": false; }; "value": { "alias": "value"; "required": false; }; }, {}, never, never, false, never>;
5757
// (undocumented)
58-
static ɵfac: i0.ɵɵFactoryDeclaration<MatLegacyProgressSpinner, [null, null, { optional: true; }, { optional: true; }, null, null, null, null]>;
58+
static ɵfac: i0.ɵɵFactoryDeclaration<MatLegacyProgressSpinner, [null, null, { optional: true; }, { optional: true; }, null, null, null, null, { optional: true; }]>;
5959
}
6060

6161
export { MatLegacyProgressSpinnerDefaultOptions }

0 commit comments

Comments
 (0)