Skip to content

Commit

Permalink
Copy of n_clicks change
Browse files Browse the repository at this point in the history
  • Loading branch information
Lxstr committed Dec 10, 2023
1 parent 26bf6ab commit c119924
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions components/dash-core-components/src/components/Clipboard.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class Clipboard extends React.Component {
constructor(props) {
super(props);
this.copyToClipboard = this.copyToClipboard.bind(this);
this.onClickHandler = this.onClickHandler.bind(this);
this.copySuccess = this.copySuccess.bind(this);
this.getTargetText = this.getTargetText.bind(this);
this.loading = this.loading.bind(this);
Expand All @@ -26,12 +27,19 @@ export default class Clipboard extends React.Component {
};
}

onClickHandler() {
this.props.setProps({n_clicks: this.props.n_clicks + 1});
}

componentDidUpdate(prevProps) {
// If the data hasn't changed, do nothing.
if (!this.props.content || this.props.content === prevProps.content) {
// If the clicks has not changed, do nothing
if (
!this.props.n_clicks ||
this.props.n_clicks === prevProps.n_clicks
) {
return;
}
// If the data has changed, copy to clipboard
// If the clicks has changed, copy to clipboard
this.copyToClipboard();
}

Expand Down Expand Up @@ -94,10 +102,6 @@ export default class Clipboard extends React.Component {
}

async copyToClipboard() {
this.props.setProps({
n_clicks: this.props.n_clicks + 1,
});

let content;
let htmlContent;
if (this.props.target_id) {
Expand Down Expand Up @@ -131,7 +135,7 @@ export default class Clipboard extends React.Component {
title={title}
style={style}
className={className}
onClick={this.copyToClipboard}
onClick={this.onClickHandler}
data-dash-is-loading={
(loading_state && loading_state.is_loading) || undefined
}
Expand Down

0 comments on commit c119924

Please sign in to comment.