@@ -120,7 +120,8 @@ class ClipboardCopy extends React.Component<ClipboardCopyProps, ClipboardCopySta
120
120
// eslint-disable-next-line @typescript-eslint/no-unused-vars
121
121
componentDidUpdate = ( prevProps : ClipboardCopyProps , prevState : ClipboardCopyState ) => {
122
122
if ( prevProps . children !== this . props . children ) {
123
- this . setState ( { text : this . props . children as string } ) ;
123
+ const newText = this . props . children as string ;
124
+ this . setState ( { text : newText , textWhenExpanded : newText } ) ;
124
125
}
125
126
} ;
126
127
@@ -252,7 +253,7 @@ class ClipboardCopy extends React.Component<ClipboardCopyProps, ClipboardCopySta
252
253
< TextInput
253
254
readOnlyVariant = { isReadOnly || this . state . expanded ? 'default' : undefined }
254
255
onChange = { this . updateText }
255
- value = { this . state . text }
256
+ value = { this . state . expanded ? this . state . textWhenExpanded : this . state . text }
256
257
id = { `text-input-${ id } ` }
257
258
aria-label = { textAriaLabel }
258
259
{ ...( isCode && { dir : 'ltr' } ) }
@@ -266,7 +267,7 @@ class ClipboardCopy extends React.Component<ClipboardCopyProps, ClipboardCopySta
266
267
textId = { `text-input-${ id } ` }
267
268
aria-label = { hoverTip }
268
269
onClick = { ( event : any ) => {
269
- onCopy ( event , this . state . text ) ;
270
+ onCopy ( event , this . state . expanded ? this . state . textWhenExpanded : this . state . text ) ;
270
271
this . setState ( { copied : true } ) ;
271
272
} }
272
273
onTooltipHidden = { ( ) => this . setState ( { copied : false } ) }
0 commit comments