Skip to content

Commit 08169bc

Browse files
Fix #805 don't blur() the trigger after a clipboard action (#807)
* 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)
1 parent c7c7fda commit 08169bc

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/clipboard.js

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class Clipboard extends Emitter {
8686
if (trigger) {
8787
trigger.focus();
8888
}
89-
document.activeElement.blur();
9089
window.getSelection().removeAllRanges();
9190
},
9291
});

test/clipboard.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,16 @@ describe('Clipboard', () => {
171171
});
172172

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

177177
clipboard.on('success', (e) => {
178+
e.clearSelection();
179+
178180
let selectedElem = document.activeElement;
179181
let selectedText = window.getSelection().toString();
180182

181-
e.clearSelection();
182-
183-
assert.equal(selectedElem, document.body);
183+
assert.equal(selectedElem, e.trigger);
184184
assert.equal(selectedText, '');
185185

186186
done();

0 commit comments

Comments
 (0)