anyone-oslo/pages

View on GitHub
app/javascript/lib/copyToClipboard.ts

Summary

Maintainability
A
0 mins
Test Coverage
export function copySupported() {
  return (
    document.queryCommandSupported && document.queryCommandSupported("copy")
  );
}

export default function copyToClipboard(str: string) {
  const el = document.createElement("textarea");
  el.value = str;
  document.body.appendChild(el);
  el.select();
  document.execCommand("copy");
  document.body.removeChild(el);
}