@@ -43,7 +43,9 @@ export enum SnippetType {
43
43
[ngClass]="{
44
44
'cds--snippet--light': theme === 'light'
45
45
}">
46
- <ng-container *ngTemplateOutlet="codeTemplate"></ng-container>
46
+ <code #code>
47
+ <ng-container *ngTemplateOutlet="codeTemplate"></ng-container>
48
+ </code>
47
49
</span>
48
50
</ng-template>
49
51
</ng-container>
@@ -68,7 +70,7 @@ export enum SnippetType {
68
70
<pre
69
71
#codeContent
70
72
*ngIf="!skeleton"
71
- (scroll)="(display === 'multi' ? handleScroll() : null)"><ng-container *ngTemplateOutlet="codeTemplate"></ng-container></pre>
73
+ (scroll)="(display === 'multi' ? handleScroll() : null)"><code #code>< ng-container *ngTemplateOutlet="codeTemplate"></ng-container></code ></pre>
72
74
</div>
73
75
<div *ngIf="hasLeft" class="cds--snippet__overflow-indicator--left"></div>
74
76
<div *ngIf="hasRight" class="cds--snippet__overflow-indicator--right"></div>
@@ -114,7 +116,9 @@ export enum SnippetType {
114
116
'tabindex': '0'
115
117
}">
116
118
<ng-container *ngIf="display === 'inline'">
117
- <ng-container *ngTemplateOutlet="codeTemplate"></ng-container>
119
+ <code #code>
120
+ <ng-container *ngTemplateOutlet="codeTemplate"></ng-container>
121
+ </code>
118
122
</ng-container>
119
123
<ng-container *ngIf="display !== 'inline'">
120
124
<svg cdsIcon="copy" size="16" class="cds--snippet__icon"></svg>
@@ -123,7 +127,7 @@ export enum SnippetType {
123
127
</ng-template>
124
128
125
129
<ng-template #codeTemplate>
126
- <code #code>< ng-content></ng-content></code >
130
+ <ng-content></ng-content>
127
131
</ng-template>
128
132
`
129
133
} )
@@ -228,6 +232,10 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
228
232
}
229
233
230
234
handleScroll ( ) {
235
+ if ( this . skeleton ) {
236
+ return ;
237
+ }
238
+
231
239
let ref ;
232
240
switch ( this . display ) {
233
241
case "multi" :
@@ -259,7 +267,7 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
259
267
onCopyButtonClicked ( ) {
260
268
if ( ! this . disabled ) {
261
269
window . navigator . clipboard
262
- . writeText ( this . code . nativeElement . innerText || this . code . nativeElement . textContent ) . then ( ( ) => {
270
+ . writeText ( this . code ) . then ( ( ) => {
263
271
this . showFeedback = true ;
264
272
this . animating = true ;
265
273
setTimeout ( ( ) => {
@@ -272,6 +280,11 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
272
280
273
281
ngOnInit ( ) {
274
282
this . calculateContainerHeight ( ) ;
283
+ }
284
+
285
+ ngAfterViewInit ( ) {
286
+ this . canExpand ( ) ;
287
+ this . handleScroll ( ) ;
275
288
if ( window ) {
276
289
this . eventService . on ( window as any , "resize" , ( ) => {
277
290
this . canExpand ( ) ;
@@ -280,15 +293,8 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
280
293
}
281
294
}
282
295
283
- ngAfterViewInit ( ) {
284
- setTimeout ( ( ) => {
285
- this . canExpand ( ) ;
286
- this . handleScroll ( ) ;
287
- } ) ;
288
- }
289
-
290
296
calculateContainerHeight ( ) {
291
- if ( this . display === "multi" ) {
297
+ if ( this . display === "multi" && ! this . skeleton ) {
292
298
this . styles = { } ;
293
299
if ( this . expanded ) {
294
300
if ( this . maxExpandedNumberOfRows > 0 ) {
@@ -309,7 +315,7 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
309
315
}
310
316
311
317
protected canExpand ( ) {
312
- if ( this . display === "multi" ) {
318
+ if ( this . display === "multi" && ! this . skeleton ) {
313
319
const height = this . codeContent . nativeElement . getBoundingClientRect ( ) . height ;
314
320
if (
315
321
this . maxCollapsedNumberOfRows > 0 &&
0 commit comments