Skip to content

Commit e78d058

Browse files
crisbetoangular-robot[bot]
authored andcommitted
fix(cdk-experimental/column-resize): avoid CSP errors
Uses the new `CSP_NONCE` token to avoid errors when inserting `style` tags dynamically in the column resize package.
1 parent 2172445 commit e78d058

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/cdk-experimental/column-resize/resize-strategy.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Inject, Injectable, OnDestroy, Provider} from '@angular/core';
9+
import {Inject, Injectable, OnDestroy, Provider, CSP_NONCE, Optional} from '@angular/core';
1010
import {DOCUMENT} from '@angular/common';
1111
import {coerceCssPixelValue} from '@angular/cdk/coercion';
1212
import {CdkTable, _CoalescedStyleScheduler, _COALESCED_STYLE_SCHEDULER} from '@angular/cdk/table';
@@ -144,6 +144,7 @@ export class CdkFlexTableResizeStrategy extends ResizeStrategy implements OnDest
144144
protected readonly styleScheduler: _CoalescedStyleScheduler,
145145
protected readonly table: CdkTable<unknown>,
146146
@Inject(DOCUMENT) document: any,
147+
@Inject(CSP_NONCE) @Optional() private readonly _nonce?: string | null,
147148
) {
148149
super();
149150
this._document = document;
@@ -235,6 +236,11 @@ export class CdkFlexTableResizeStrategy extends ResizeStrategy implements OnDest
235236
private _getStyleSheet(): CSSStyleSheet {
236237
if (!this._styleElement) {
237238
this._styleElement = this._document.createElement('style');
239+
240+
if (this._nonce) {
241+
this._styleElement.nonce = this._nonce;
242+
}
243+
238244
this._styleElement.appendChild(this._document.createTextNode(''));
239245
this._document.head.appendChild(this._styleElement);
240246
}

src/material-experimental/column-resize/resize-strategy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {Inject, Injectable, Provider} from '@angular/core';
9+
import {CSP_NONCE, Inject, Injectable, Optional, Provider} from '@angular/core';
1010
import {DOCUMENT} from '@angular/common';
1111
import {CdkTable, _CoalescedStyleScheduler, _COALESCED_STYLE_SCHEDULER} from '@angular/cdk/table';
1212

@@ -29,8 +29,9 @@ export class MatFlexTableResizeStrategy extends CdkFlexTableResizeStrategy {
2929
@Inject(_COALESCED_STYLE_SCHEDULER) styleScheduler: _CoalescedStyleScheduler,
3030
table: CdkTable<unknown>,
3131
@Inject(DOCUMENT) document: any,
32+
@Inject(CSP_NONCE) @Optional() nonce?: string | null,
3233
) {
33-
super(columnResize, styleScheduler, table, document);
34+
super(columnResize, styleScheduler, table, document, nonce);
3435
}
3536

3637
protected override getColumnCssClass(cssFriendlyColumnName: string): string {

0 commit comments

Comments
 (0)