Skip to content

Commit

Permalink
Copy to clipboard: handle case where clicks button again immediately
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwatkins0 committed Oct 28, 2020
1 parent ddf5ec4 commit 47fc7be
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion assets/src/amp-validation/copy-to-clipboard-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@ import { getURLValidationTableRows } from './get-url-validation-table-rows';
*/
function onSuccess( { trigger } ) {
trigger.focus();

const newInnerText = __( 'Copied to clipboard', 'amp' );

// Exit if the user has already clicked the button and we are still within the
// 4000ms before the setTimeout callback runs.
if ( trigger.innerText === newInnerText ) {
return;
}

const originalText = trigger.innerText;
trigger.innerText = __( 'Copied to clipboard', 'amp' );
trigger.innerText = newInnerText;

setTimeout( () => {
if ( document.body.contains( trigger ) ) {
Expand Down

0 comments on commit 47fc7be

Please sign in to comment.