Skip to content

Commit

Permalink
Merge pull request #2875 from Akshat55/snippet-fix
Browse files Browse the repository at this point in the history
fix: copy inner text or text content of code element
  • Loading branch information
zvonimirfras authored May 9, 2024
2 parents eaebf28 + 8032db3 commit f114db5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/code-snippet/code-snippet.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
onCopyButtonClicked() {
if (!this.disabled) {
window.navigator.clipboard
.writeText(this.code).then(() => {
.writeText(this.code.nativeElement.innerText || this.code.nativeElement.textContent).then(() => {
this.showFeedback = true;
this.animating = true;
setTimeout(() => {
Expand Down
14 changes: 7 additions & 7 deletions src/code-snippet/code-snippet.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
})
],
argTypes: {
code: {
snippet: {
control: false
},
display: {
Expand Down Expand Up @@ -42,34 +42,34 @@ export default {
const Template = (args) => ({
props: args,
template: `
<cds-code-snippet display="single">{{code}}</cds-code-snippet>
<cds-code-snippet display="single">{{snippet}}</cds-code-snippet>
`
});
export const Basic = Template.bind({});
Basic.args = {
code: `import { UIShellModule } from 'carbon-components-angular'; // Single line of code`
snippet: `import { UIShellModule } from 'carbon-components-angular'; // Single line of code`
};

const InlineTemplate = (args) => ({
props: args,
template: `
Here is some <cds-code-snippet display="inline" [theme]="theme">{{code}}</cds-code-snippet> for you.
Here is some <cds-code-snippet display="inline" [theme]="theme">{{snippet}}</cds-code-snippet> for you.
`
});
export const Inline = InlineTemplate.bind({});
Inline.args = {
code: "<inline code>"
snippet: "<inline code>"
};

const MultiTemplate = (args) => ({
props: args,
template: `
<cds-code-snippet display="multi">{{code}}</cds-code-snippet>
<cds-code-snippet display="multi">{{snippet}}</cds-code-snippet>
`
});
export const Multi = MultiTemplate.bind({});
Multi.args = {
code: `{
snippet: `{
"name": "carbon-components-angular",
"version": "0.0.0",
"description": "Next generation components",
Expand Down

0 comments on commit f114db5

Please sign in to comment.