-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copied text has yellow background when pasted into gmail or google docs. #42
Comments
wow looks like text is copied as rich text. I suppose the place you copy it from has yellow background, right? |
It doesn't. I'm copying the text from a standard input. |
Any example how to reproduce this? |
oh actually it works like that from codepen example! |
Opened issue in upstream sudodoki/copy-to-clipboard#43 |
sudodoki/copy-to-clipboard#43 (comment)
|
Published |
Thank you for your help! |
No worries 👌 |
Same (with the light gray). Is there a fix for this - I can't use it, as it does this. Please let me know. Thanks a bunch. |
Browsers keep doing some awkward stuff... |
Can't reproduce anymore. Works well for me in several browsers. |
So this is still an issue in copy-to-clipboard dependency (still happens to me in Chrome): sudodoki/copy-to-clipboard#46, but there is a workaround. My implementation of the workaround: //your-component.js
<CopyToClipboard key="copy" text={`CopyToClipboard\n${textYouWantToCopy}`}>
Copy text
</CopyToClipboard>
//main.js
document.addEventListener('copy', e => {
const textContent = e.target.textContent;
const filterText = 'CopyToClipboard\n';
if (textContent.startsWith(filterText)) {
e.clipboardData.setData('text/plain', textContent.replace(filterText, ''));
e.preventDefault();
}
}); |
@nkbt I'm thinking that this might be added inside react-copy-to-clipboard, either behind the boolean property or even as a default behavior. |
Also not sure if that matters but for me issue is happening when text attribute has multi line string for example: <CopyToClipboard key="copy" text={`blah\nblah\nblah`}>
Copy text
</CopyToClipboard> Example above would have a background (inherits color from body & background from html elements). However when it is not a multi-line string, no problem. |
Thanks @szarouski for all the examples! |
I've updated http://nkbt.github.io/react-copy-to-clipboard/ to have multiline textarea and tried to paste to google docs - no issues. Do I need to do something else to reproduce it? I also updated https://codepen.io/nkbt/pen/eNPoQv?editors=0010, so if you can clone it and make "buggy" - that would be great |
I managed to reproduce the issue with this pen: https://codepen.io/anon/pen/aKMRxO. The buggy behaviour happens when copying from Chrome to Google Docs or Microsoft Word. |
A cleaner workaround: onCopy(copiedText) {
navigator.clipboard.writeText(copiedText)
}
render() {
return (
<CopyToClipboard onCopy={this.onCopy} key="copy" text={`some\ntext\nhere`}>
Copy text
</CopyToClipboard>
)
} |
any help here? |
@anilljoshi The underlying package (copy-to-clipboard) has been updated, and you can now pass along a format in the options prop to avoid capturing some of the underlying styles.
Works like a charm :) |
Do you know what might cause this and if there is a way to make that not happen?
The text was updated successfully, but these errors were encountered: