Skip to content

Commit

Permalink
fix: wrong preventDefault
Browse files Browse the repository at this point in the history
  • Loading branch information
tangqiulin committed Apr 14, 2023
1 parent 113cb35 commit 47bd892
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
20 changes: 20 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ <h2 id="basic-text">Basic text copy</h2>
</div>
</div>
<hr>
<div class="container">
<h2 id="copy-with-callback">Copy with callback</h2>
<textarea disabled class="code half">copyToClipboard("Copy with callback", { onCopy: noop })</textarea>
<div class="half">
<button data-test="init-copy-with-callback">Click to copy sample text</button>
</div>
</div>
<hr>
<div class="container">
<h2 id="multiline-text">Multiline text copy</h2>
<textarea disabled class="code half">
Expand Down Expand Up @@ -45,6 +53,18 @@ <h2 id="multiline-markup">Markup + text copy</h2>
.addEventListener('click', function () {
copyToClipboard("Hello, I'm new content from your clipboard")
});
(function() {
var container = document.querySelector('#copy-with-callback + textarea');
var noop = function noop() {
// do nothing
};
document.querySelector('#copy-with-callback ~ .half button')
.addEventListener('click', function () {
copyToClipboard(container.textContent, {
onCopy: noop,
})
})
})();
(function() {
var multilineContainer = document.querySelector('#multiline-text + textarea');
document.querySelector('#multiline-text ~ .half button')
Expand Down
2 changes: 1 addition & 1 deletion example/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ function copy(text, options) {
}
}
if (options.onCopy) {
e.preventDefault();
options.onCopy(e.clipboardData);
}
});
Expand Down
12 changes: 12 additions & 0 deletions tests/02_copy-with-callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';
module.exports = {
'Copy With Callback' : function (browser) {
browser
.page.helper().resetBuffer()
.url(browser.launchUrl)
.waitForElementVisible('[data-test="init-copy-with-callback"]', 1000)
.click('[data-test="init-copy-with-callback"]')
.assert.assertBuffer("copyToClipboard(\"Copy with callback\", { onCopy: noop })")
.end();
}
};

0 comments on commit 47bd892

Please sign in to comment.