Skip to content

Commit

Permalink
fix(ClipboardCopy): update main content on children change when expan…
Browse files Browse the repository at this point in the history
…ded (#10015)
  • Loading branch information
adamviktora committed Jan 17, 2024
1 parent c856b07 commit 9395dd5
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class ClipboardCopy extends React.Component<ClipboardCopyProps, ClipboardCopySta
// eslint-disable-next-line @typescript-eslint/no-unused-vars
componentDidUpdate = (prevProps: ClipboardCopyProps, prevState: ClipboardCopyState) => {
if (prevProps.children !== this.props.children) {
this.setState({ text: this.props.children as string });
const newText = this.props.children as string;
this.setState({ text: newText, textWhenExpanded: newText });
}
};

Expand Down Expand Up @@ -252,7 +253,7 @@ class ClipboardCopy extends React.Component<ClipboardCopyProps, ClipboardCopySta
<TextInput
readOnlyVariant={isReadOnly || this.state.expanded ? 'default' : undefined}
onChange={this.updateText}
value={this.state.text}
value={this.state.expanded ? this.state.textWhenExpanded : this.state.text}
id={`text-input-${id}`}
aria-label={textAriaLabel}
{...(isCode && { dir: 'ltr' })}
Expand All @@ -266,7 +267,7 @@ class ClipboardCopy extends React.Component<ClipboardCopyProps, ClipboardCopySta
textId={`text-input-${id}`}
aria-label={hoverTip}
onClick={(event: any) => {
onCopy(event, this.state.text);
onCopy(event, this.state.expanded ? this.state.textWhenExpanded : this.state.text);
this.setState({ copied: true });
}}
onTooltipHidden={() => this.setState({ copied: false })}
Expand Down

0 comments on commit 9395dd5

Please sign in to comment.