diff --git a/src/clipboard-action.js b/src/clipboard-action.js index 6b578f3..c86eda1 100644 --- a/src/clipboard-action.js +++ b/src/clipboard-action.js @@ -51,13 +51,15 @@ export default class ClipboardAction { * and makes a selection on it. */ selectFake() { + let isRTL = document.documentElement.getAttribute('dir') == 'rtl'; + this.removeFake(); this.fakeHandler = document.body.addEventListener('click', () => this.removeFake()); this.fakeElem = document.createElement('textarea'); this.fakeElem.style.position = 'absolute'; - this.fakeElem.style.left = '-9999px'; + this.fakeElem.style[ isRTL ? 'right' : 'left' ] = '-9999px'; this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px'; this.fakeElem.setAttribute('readonly', ''); this.fakeElem.value = this.text; diff --git a/test/clipboard-action.js b/test/clipboard-action.js index b1b5781..4797abb 100644 --- a/test/clipboard-action.js +++ b/test/clipboard-action.js @@ -57,6 +57,19 @@ describe('ClipboardAction', () => { done(); } }); + + it('should set the position right style property', done => { + // Set document direction + document.documentElement.setAttribute('dir', 'rtl'); + + let clip = new ClipboardAction({ + emitter: new Emitter(), + text: 'foo' + }); + + assert.equal(clip.fakeElem.style.right, '-9999px'); + done(); + }); }); describe('#set action', () => {