diff --git a/src/clipboard.js b/src/clipboard.js index da513be..1b3a71f 100644 --- a/src/clipboard.js +++ b/src/clipboard.js @@ -47,10 +47,10 @@ class Clipboard extends Emitter { } this.clipboardAction = new ClipboardAction({ - action : this.action(e.target), - target : this.target(e.target), - text : this.text(e.target), - trigger : e.target, + action : this.action(e.currentTarget), + target : this.target(e.currentTarget), + text : this.text(e.currentTarget), + trigger : e.currentTarget, emitter : this }); } diff --git a/test/clipboard.js b/test/clipboard.js index c3ffcea..bb6dd5b 100644 --- a/test/clipboard.js +++ b/test/clipboard.js @@ -9,8 +9,14 @@ describe('Clipboard', () => { global.button.setAttribute('data-clipboard-text', 'foo'); document.body.appendChild(global.button); + global.span = document.createElement('span'); + global.span.innerHTML = 'bar'; + + global.button.appendChild(span); + global.event = { - target: global.button + target: global.button, + currentTarget: global.button }; }); @@ -63,6 +69,14 @@ describe('Clipboard', () => { assert.instanceOf(clipboard.clipboardAction, ClipboardAction); }); + it('should use an event\'s currentTarget when not equal to target', () => { + let clipboard = new Clipboard('.btn'); + let bubbledEvent = { target: global.span, currentTarget: global.button }; + + clipboard.onClick(bubbledEvent); + assert.instanceOf(clipboard.clipboardAction, ClipboardAction); + }); + it('should throws exception target', done => { try { var clipboard = new Clipboard('.btn', {