Skip to content

Commit

Permalink
fix(cdk-experimental/table-scroll-container): avoid CSP errors
Browse files Browse the repository at this point in the history
Adds a nonce to the `style` tag generated by the table scroll container to avoid CSP errors.
  • Loading branch information
crisbeto authored and angular-robot[bot] committed Apr 14, 2023
1 parent 0d56af5 commit 412c691
Showing 1 changed file with 7 additions and 1 deletion.
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Directive, ElementRef, Inject, OnDestroy, OnInit, Optional} from '@angular/core';
import {CSP_NONCE, Directive, ElementRef, Inject, OnDestroy, OnInit, Optional} from '@angular/core';
import {DOCUMENT} from '@angular/common';
import {Directionality} from '@angular/cdk/bidi';
import {_getShadowRoot} from '@angular/cdk/platform';
Expand Down Expand Up @@ -52,6 +52,7 @@ export class CdkTableScrollContainer implements StickyPositioningListener, OnDes
private readonly _elementRef: ElementRef<HTMLElement>,
@Inject(DOCUMENT) private readonly _document: Document,
@Optional() private readonly _directionality?: Directionality,
@Optional() @Inject(CSP_NONCE) private readonly _nonce?: string | null,
) {
this._uniqueClassName = `cdk-table-scroll-container-${++nextId}`;
_elementRef.nativeElement.classList.add(this._uniqueClassName);
Expand Down Expand Up @@ -114,6 +115,11 @@ export class CdkTableScrollContainer implements StickyPositioningListener, OnDes
private _getStyleSheet(): CSSStyleSheet {
if (!this._styleElement) {
this._styleElement = this._document.createElement('style');

if (this._nonce) {
this._styleElement.nonce = this._nonce;
}

this._styleRoot.appendChild(this._styleElement);
}

Expand Down

0 comments on commit 412c691

Please sign in to comment.