@@ -43,7 +43,9 @@ export enum SnippetType {
4343 [ngClass]="{
4444 'cds--snippet--light': theme === 'light'
4545 }">
46- <ng-container *ngTemplateOutlet="codeTemplate"></ng-container>
46+ <code #code>
47+ <ng-container *ngTemplateOutlet="codeTemplate"></ng-container>
48+ </code>
4749 </span>
4850 </ng-template>
4951 </ng-container>
@@ -68,7 +70,7 @@ export enum SnippetType {
6870 <pre
6971 #codeContent
7072 *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>
7274 </div>
7375 <div *ngIf="hasLeft" class="cds--snippet__overflow-indicator--left"></div>
7476 <div *ngIf="hasRight" class="cds--snippet__overflow-indicator--right"></div>
@@ -114,7 +116,9 @@ export enum SnippetType {
114116 'tabindex': '0'
115117 }">
116118 <ng-container *ngIf="display === 'inline'">
117- <ng-container *ngTemplateOutlet="codeTemplate"></ng-container>
119+ <code #code>
120+ <ng-container *ngTemplateOutlet="codeTemplate"></ng-container>
121+ </code>
118122 </ng-container>
119123 <ng-container *ngIf="display !== 'inline'">
120124 <svg cdsIcon="copy" size="16" class="cds--snippet__icon"></svg>
@@ -123,7 +127,7 @@ export enum SnippetType {
123127 </ng-template>
124128
125129 <ng-template #codeTemplate>
126- <code #code>< ng-content></ng-content></code >
130+ <ng-content></ng-content>
127131 </ng-template>
128132 `
129133} )
@@ -228,6 +232,10 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
228232 }
229233
230234 handleScroll ( ) {
235+ if ( this . skeleton ) {
236+ return ;
237+ }
238+
231239 let ref ;
232240 switch ( this . display ) {
233241 case "multi" :
@@ -259,7 +267,7 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
259267 onCopyButtonClicked ( ) {
260268 if ( ! this . disabled ) {
261269 window . navigator . clipboard
262- . writeText ( this . code . nativeElement . innerText || this . code . nativeElement . textContent ) . then ( ( ) => {
270+ . writeText ( this . code ) . then ( ( ) => {
263271 this . showFeedback = true ;
264272 this . animating = true ;
265273 setTimeout ( ( ) => {
@@ -272,6 +280,11 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
272280
273281 ngOnInit ( ) {
274282 this . calculateContainerHeight ( ) ;
283+ }
284+
285+ ngAfterViewInit ( ) {
286+ this . canExpand ( ) ;
287+ this . handleScroll ( ) ;
275288 if ( window ) {
276289 this . eventService . on ( window as any , "resize" , ( ) => {
277290 this . canExpand ( ) ;
@@ -280,15 +293,8 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
280293 }
281294 }
282295
283- ngAfterViewInit ( ) {
284- setTimeout ( ( ) => {
285- this . canExpand ( ) ;
286- this . handleScroll ( ) ;
287- } ) ;
288- }
289-
290296 calculateContainerHeight ( ) {
291- if ( this . display === "multi" ) {
297+ if ( this . display === "multi" && ! this . skeleton ) {
292298 this . styles = { } ;
293299 if ( this . expanded ) {
294300 if ( this . maxExpandedNumberOfRows > 0 ) {
@@ -309,7 +315,7 @@ export class CodeSnippet extends BaseIconButton implements OnInit, AfterViewInit
309315 }
310316
311317 protected canExpand ( ) {
312- if ( this . display === "multi" ) {
318+ if ( this . display === "multi" && ! this . skeleton ) {
313319 const height = this . codeContent . nativeElement . getBoundingClientRect ( ) . height ;
314320 if (
315321 this . maxCollapsedNumberOfRows > 0 &&
0 commit comments