| 1 |
/** |
| 2 |
* Creates a fake textarea element with a value. |
| 3 |
* @param {String} value |
| 4 |
* @return {HTMLElement} |
| 5 |
*/ |
| 6 |
export default function createFakeElement(value) { |
| 7 |
const isRTL = document.documentElement.getAttribute('dir') === 'rtl'; |
| 8 |
const fakeElement = document.createElement('textarea'); |
| 9 |
// Prevent zooming on iOS |
| 10 |
fakeElement.style.fontSize = '12pt'; |
| 11 |
// Reset box model |
| 12 |
fakeElement.style.border = '0'; |
| 13 |
fakeElement.style.padding = '0'; |
| 14 |
fakeElement.style.margin = '0'; |
| 15 |
// Move element out of screen horizontally |
| 16 |
fakeElement.style.position = 'absolute'; |
| 17 |
fakeElement.style[isRTL ? 'right' : 'left'] = '-9999px'; |
| 18 |
// Move element to the same position vertically |
| 19 |
let yPosition = window.pageYOffset || document.documentElement.scrollTop; |
| 20 |
fakeElement.style.top = `${yPosition}px`; |
| 21 |
|
| 22 |
fakeElement.setAttribute('readonly', ''); |
| 23 |
fakeElement.value = value; |
| 24 |
|
| 25 |
return fakeElement; |
| 26 |
} |