Skip to content
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

Open
rlpacht opened this issue Aug 12, 2016 · 22 comments
Open

Comments

@rlpacht
Copy link

rlpacht commented Aug 12, 2016

Do you know what might cause this and if there is a way to make that not happen?

@nkbt
Copy link
Owner

nkbt commented Aug 12, 2016

wow

looks like text is copied as rich text. I suppose the place you copy it from has yellow background, right?

@rlpacht
Copy link
Author

rlpacht commented Aug 12, 2016

It doesn't. I'm copying the text from a standard input.

@nkbt
Copy link
Owner

nkbt commented Aug 12, 2016

Any example how to reproduce this?

@nkbt
Copy link
Owner

nkbt commented Aug 12, 2016

oh actually it works like that from codepen example!

@nkbt
Copy link
Owner

nkbt commented Aug 12, 2016

Opened issue in upstream sudodoki/copy-to-clipboard#43

@nkbt
Copy link
Owner

nkbt commented Aug 16, 2016

sudodoki/copy-to-clipboard#43 (comment)

copy-to-clipboard@3.0.5 is published with the fix.
Please, update your dependencies and problem should go away

@nkbt nkbt closed this as completed in 84a44eb Aug 16, 2016
@nkbt
Copy link
Owner

nkbt commented Aug 16, 2016

Published react-copy-to-clipboard@4.2.3 with updated libs

@rlpacht
Copy link
Author

rlpacht commented Aug 16, 2016

Thank you for your help!

@nkbt
Copy link
Owner

nkbt commented Aug 17, 2016

No worries 👌

@davidkaminsky
Copy link

davidkaminsky commented Sep 6, 2016

I'm using version 4.2.3 and I'm still seeing this it's just that the background is light grey now. Is this expected? There is no grey background for the text. Attached are some screenshots.

screen shot 2016-09-06 at 9 49 36 am
screen shot 2016-09-06 at 9 50 23 am

@dsacramone
Copy link

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.

@nkbt
Copy link
Owner

nkbt commented Feb 11, 2017

Browsers keep doing some awkward stuff...

@nkbt nkbt reopened this Feb 11, 2017
@nkbt
Copy link
Owner

nkbt commented Apr 20, 2017

Can't reproduce anymore. Works well for me in several browsers.

@nkbt nkbt closed this as completed Apr 20, 2017
@webuniverseio
Copy link

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();
  }
});

@webuniverseio
Copy link

@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.

@webuniverseio
Copy link

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.

@nkbt nkbt reopened this Jul 12, 2017
@nkbt
Copy link
Owner

nkbt commented Jul 12, 2017

Thanks @szarouski for all the examples!

@nkbt
Copy link
Owner

nkbt commented Sep 30, 2017

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

@wdlb
Copy link

wdlb commented Jul 3, 2018

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.

@alexisig
Copy link

alexisig commented Nov 7, 2018

A cleaner workaround:

onCopy(copiedText) {
    navigator.clipboard.writeText(copiedText)
}

render() {
    return (
        <CopyToClipboard onCopy={this.onCopy} key="copy" text={`some\ntext\nhere`}>
            Copy text
        </CopyToClipboard>
    )
}

@mrjosshi
Copy link

mrjosshi commented Jul 6, 2019

any help here?

@nikkirostollan
Copy link

nikkirostollan commented Jul 18, 2019

@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.

  1. Check you're yarn-lock or package-lock to see if your version for copy-to-clipboard is 3.2.0 or higher, then upgrade as necessary.

  2. Pass the options prop an object containing:{format: 'text/plain'}

<CopyToClipboard onCopy={this.onCopy} text={text} options={{format: 'text/plain'}}>
{...children}
</CopyToClipbaord>

Works like a charm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants