Skip to content

Commit

Permalink
Fix #805 don't blur() the trigger after a clipboard action (#807)
Browse files Browse the repository at this point in the history
* Remove the `blur()` following a clipboard action

It's pointless to set `focus()` on the trigger first, if in the next step you're just going to `blur()` the active element anyway.

* Tweak test to not expect active element to be body

Since it's now not `blur()`ing anymore

* Fix test

see #807 (comment)
  • Loading branch information
patrickhlauke authored May 4, 2022
1 parent c7c7fda commit 08169bc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class Clipboard extends Emitter {
if (trigger) {
trigger.focus();
}
document.activeElement.blur();
window.getSelection().removeAllRanges();
},
});
Expand Down
8 changes: 4 additions & 4 deletions test/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ describe('Clipboard', () => {
});

describe('#clearSelection', () => {
it('should remove focus from target and text selection', (done) => {
it('should clear text selection without moving focus', (done) => {
let clipboard = new Clipboard('.btn');

clipboard.on('success', (e) => {
e.clearSelection();

let selectedElem = document.activeElement;
let selectedText = window.getSelection().toString();

e.clearSelection();

assert.equal(selectedElem, document.body);
assert.equal(selectedElem, e.trigger);
assert.equal(selectedText, '');

done();
Expand Down

0 comments on commit 08169bc

Please sign in to comment.