Skip to content

Commit 2eaf2db

Browse files
authored
Add cspNonce argument to Hds::CodeEditor component (#3132)
1 parent 41b30d6 commit 2eaf2db

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

.changeset/brown-ways-invite.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@hashicorp/design-system-components": minor
3+
---
4+
5+
<!-- START components/code-editor -->
6+
7+
`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
8+
9+
<!-- END -->

packages/components/src/components/hds/code-editor/index.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
ariaDescribedBy=this.ariaDescribedBy
5656
ariaLabel=@ariaLabel
5757
ariaLabelledBy=this.ariaLabelledBy
58+
cspNonce=@cspNonce
5859
extraKeys=@extraKeys
5960
hasLineWrapping=@hasLineWrapping
6061
isLintingEnabled=@isLintingEnabled

showcase/tests/integration/components/hds/code-editor/index-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ module('Integration | Component | hds/code-editor/index', function (hooks) {
2424
assert.dom('#test-code-editor').hasClass('hds-code-editor');
2525
});
2626

27+
// cspNonce
28+
test('it should render the injected style tag with the provided `@cspNonce` value', async function (assert) {
29+
const cspNonce = 'csp-nonce-123';
30+
31+
this.set('cspNonce', cspNonce);
32+
33+
await setupCodeEditor(
34+
hbs`<Hds::CodeEditor @cspNonce={{this.cspNonce}} as |CE|><CE.Title>Test Title</CE.Title></Hds::CodeEditor>`,
35+
);
36+
37+
// can't use assert.dom to access elements in head
38+
assert.ok(document.querySelector(`style[nonce="${cspNonce}"]`));
39+
});
40+
2741
// title
2842
test('it should render the component with a title using the default tag', async function (assert) {
2943
await setupCodeEditor(

0 commit comments

Comments
 (0)