diff --git a/.changeset/brown-ways-invite.md b/.changeset/brown-ways-invite.md new file mode 100644 index 00000000000..9dc87592b53 --- /dev/null +++ b/.changeset/brown-ways-invite.md @@ -0,0 +1,9 @@ +--- +"@hashicorp/design-system-components": minor +--- + + + +`CodeEditor` - Added a `cspNonce` argument which passes a value of the same name to the `hds-code-editor` modifier. `cspNonce` is used to add a nonce value to the style tag + + diff --git a/packages/components/src/components/hds/code-editor/index.hbs b/packages/components/src/components/hds/code-editor/index.hbs index 9eecf641a7c..8a3a4c06cdc 100644 --- a/packages/components/src/components/hds/code-editor/index.hbs +++ b/packages/components/src/components/hds/code-editor/index.hbs @@ -55,6 +55,7 @@ ariaDescribedBy=this.ariaDescribedBy ariaLabel=@ariaLabel ariaLabelledBy=this.ariaLabelledBy + cspNonce=@cspNonce extraKeys=@extraKeys hasLineWrapping=@hasLineWrapping isLintingEnabled=@isLintingEnabled diff --git a/showcase/tests/integration/components/hds/code-editor/index-test.js b/showcase/tests/integration/components/hds/code-editor/index-test.js index c142fbeac47..9d1e1e768b1 100644 --- a/showcase/tests/integration/components/hds/code-editor/index-test.js +++ b/showcase/tests/integration/components/hds/code-editor/index-test.js @@ -24,6 +24,20 @@ module('Integration | Component | hds/code-editor/index', function (hooks) { assert.dom('#test-code-editor').hasClass('hds-code-editor'); }); + // cspNonce + test('it should render the injected style tag with the provided `@cspNonce` value', async function (assert) { + const cspNonce = 'csp-nonce-123'; + + this.set('cspNonce', cspNonce); + + await setupCodeEditor( + hbs`Test Title`, + ); + + // can't use assert.dom to access elements in head + assert.ok(document.querySelector(`style[nonce="${cspNonce}"]`)); + }); + // title test('it should render the component with a title using the default tag', async function (assert) { await setupCodeEditor(