The News

Sherry McGuinn is a longtime Chicago-area writer and award-winning screenwriter. Her work has appeared in The Chicago Tribune, Chicago Sun-Times, and numerous other publications. Sherry’s manager is…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Click to Copy React Component

This article is inspired by a requirement that I faced while developing an application in which we needed to make the text of label/heading etc copyable, so that they can be just copy-pasted any where. The problem is not that tough. It could easily be done by selecting the text and hitting Ctrl+C. Well, not that easy. The issue started when we had to ellipsise the content as per the UI requirement.

We ellipsise the text using css and put a title attribute on label/heading tags so that when the user wants to see the complete text and hovers over it, it appears like this.

The downside of this is that now the user can’t just select and copy the complete text. When I faced this issue I decided to develop a component which will wrap heading or label elements and enhace them with click to copy functionality. The result is following component.

Lets see how to use this component.

Now as soon as you click the label or heading tag, it will copy the complete content of tag irrespective of what is being shown on the UI. Try this and let me know about shortcomings/suggestions/alternative approaches that could have been taken in comments section. Code available at

References:

Add a comment

Related posts:

My 2018 Year in Reading

This year I beat my previous record of 69 books set in 2011 by reading 160 (!) books (28,238 pages). The breakdown: 45 (adult) novels, 23 nonfiction (mostly memoirs), 9 short story collections, 11 YA…

Tips To Deal With Male Infertility

The journey of pregnancy can be straightforward for some couples but some have to face a lot of problem and discomfort. There are many couples who don’t conceive easily in the first year of trying…

An Open Letter to My Guilty Conscience

Every town USA sent me a survey to gauge my feelings about the despicable NRA. I knew that any reply whatsoever would place me in a data bank of valuable prospects, open to ever more intense hounding…