Merge pull request #733 from zenorocha/feature-732-removing-dom-el

This commit is contained in:
Vitor Alencar 2021-03-01 14:07:29 +01:00 committed by GitHub
commit 15737fe877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 13 deletions

View File

@ -42,18 +42,10 @@ class ClipboardAction {
/**
* Creates a fake textarea element, sets its value from `text` property,
* and makes a selection on it.
*/
selectFake() {
createFakeElement() {
const isRTL = document.documentElement.getAttribute('dir') === 'rtl';
this.removeFake();
this.fakeHandlerCallback = () => this.removeFake();
this.fakeHandler =
this.container.addEventListener('click', this.fakeHandlerCallback) ||
true;
this.fakeElem = document.createElement('textarea');
// Prevent zooming on iOS
this.fakeElem.style.fontSize = '12pt';
@ -71,10 +63,29 @@ class ClipboardAction {
this.fakeElem.setAttribute('readonly', '');
this.fakeElem.value = this.text;
this.container.appendChild(this.fakeElem);
return this.fakeElem;
}
/**
* Get's the value of fakeElem,
* and makes a selection on it.
*/
selectFake() {
const fakeElem = this.createFakeElement();
this.fakeHandlerCallback = () => this.removeFake();
this.fakeHandler =
this.container.addEventListener('click', this.fakeHandlerCallback) ||
true;
this.container.appendChild(fakeElem);
this.selectedText = select(fakeElem);
this.selectedText = select(this.fakeElem);
this.copyText();
this.removeFake();
}
/**

View File

@ -47,7 +47,9 @@ describe('ClipboardAction', () => {
text: 'foo',
});
assert.equal(clip.fakeElem.style.right, '-9999px');
const el = clip.createFakeElement();
assert.equal(el.style.right, '-9999px');
done();
});
});
@ -90,7 +92,9 @@ describe('ClipboardAction', () => {
text: 'blah',
});
assert.equal(clip.selectedText, clip.fakeElem.value);
const el = clip.createFakeElement();
assert.equal(clip.selectedText, el.value);
});
});