question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Code Snippet copy button not working

See original GitHub issue

What package(s) are you using?

  • carbon-components
  • carbon-components-react

Detailed description

Describe in detail the issue you’re having

Is this issue related to a specific component?

  • CodeSnippet, but may affect other components that are using the copy button

What did you expect to happen? What happened instead? What would you like to see changed?

  • I expected it to copy the text snippet. It didn’t.

What browser are you working in?

  • Chrome Version 77.0.3865.120 (Official Build) (64-bit)
  • MacOS Catalina

What version of the Carbon Design System are you using?

  • Whatever’s on your demo page

What offering/product do you work on? Any pressing ship or release dates we should be aware of?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
guiguebcommented, Nov 17, 2020

@asudoh / @repjarms I thank you two for continuing to address this. We - IBM Cognos - have also ran into this issue and will benefit from the fix.

I would like to make a request. In @repjarms’s comment on Jan 30 the it was mentioned to override the onClick - and I agree this is needed. But I think there’s also a case for not overriding but to propagate the onClick.

Usecase (we have this situation):

  • client calls CodeSnippet with an onClick
  • client wants the copy-to-clipboard to happen and also receive an onClick event to do some other task

I’m not sure the best way to accomplish this. Maybe an additional prop to indicating if the copy-to-clipboard should happen (or not happen). const copyToClipboard = this.props.copyToClipboard ?? this.props.onClick ? false : true;

1reaction
asudohcommented, Oct 24, 2019

IIRC we historically let application code to do the actual copying due to the nature of requiring 3rd party library (back then). This may have changed now and feel free to implement the copying if anybody finds a cross-browser/lightweight way to do that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add copy code snippet button in React - Stack Overflow
I want users to click on a button and copy this entire code as such. But it's not working.
Read more >
Implementing copy-to-clipboard in React with Clipboard API
Improve user experience by implementing a copy-to-clipboard button in React with the JavaScript Clipboard API or with third-party libraries.
Read more >
An easy way for adding Copy to Clipboard functionality in ...
In this article, we will see how to use the most popular React library for adding copy to clipboard functionality in React app....
Read more >
Add Copy To Clipboard Button to React Syntax Highlighter
In this video series, I work on my new personal website built using React.Website: https://www.celikk.
Read more >
react-copy-to-clipboard - npm
Start using react-copy-to-clipboard in your project by running `npm i react-copy-to-clipboard`. There are 1358 other projects in the npm ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found