Skip to content

Commit 2172445

Browse files
crisbetoangular-robot[bot]
authored andcommitted
fix(cdk-experimental/table-scroll-container): avoid CSP errors
Adds a nonce to the `style` tag generated by the table scroll container to avoid CSP errors.
1 parent 86000ad commit 2172445

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/cdk-experimental/table-scroll-container/table-scroll-container.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 {Directive, ElementRef, Inject, OnDestroy, OnInit, Optional} from '@angular/core';
9+
import {CSP_NONCE, Directive, ElementRef, Inject, OnDestroy, OnInit, Optional} from '@angular/core';
1010
import {DOCUMENT} from '@angular/common';
1111
import {Directionality} from '@angular/cdk/bidi';
1212
import {_getShadowRoot} from '@angular/cdk/platform';
@@ -52,6 +52,7 @@ export class CdkTableScrollContainer implements StickyPositioningListener, OnDes
5252
private readonly _elementRef: ElementRef<HTMLElement>,
5353
@Inject(DOCUMENT) private readonly _document: Document,
5454
@Optional() private readonly _directionality?: Directionality,
55+
@Optional() @Inject(CSP_NONCE) private readonly _nonce?: string | null,
5556
) {
5657
this._uniqueClassName = `cdk-table-scroll-container-${++nextId}`;
5758
_elementRef.nativeElement.classList.add(this._uniqueClassName);
@@ -114,6 +115,11 @@ export class CdkTableScrollContainer implements StickyPositioningListener, OnDes
114115
private _getStyleSheet(): CSSStyleSheet {
115116
if (!this._styleElement) {
116117
this._styleElement = this._document.createElement('style');
118+
119+
if (this._nonce) {
120+
this._styleElement.nonce = this._nonce;
121+
}
122+
117123
this._styleRoot.appendChild(this._styleElement);
118124
}
119125

0 commit comments

Comments
 (0)