Repository URL to install this package:
|
Version:
8.0.0 ▾
|
export default (str, parent = document.body) => {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.setAttribute('contenteditable', 'true');
el.style.position = 'absolute';
el.style.left = '-9999px';
parent.appendChild(el);
el.focus();
el.select();
const range = document.createRange();
range.selectNodeContents(el);
const sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
el.setSelectionRange(0, 999999);
const copy = document.execCommand('copy');
parent.removeChild(el);
return copy;
};