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

Add the option to copy label/text to clipboard. #1055

Open
mathieu-fournier opened this issue Feb 7, 2023 · 5 comments
Open

Add the option to copy label/text to clipboard. #1055

mathieu-fournier opened this issue Feb 7, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@mathieu-fournier
Copy link

Feature

It might be a ggod addition to have the possibility to copy text to the clipboard with a single mouse press.
Components would enable it by passing something like isCopyToClipboardEnabled = true.

Examples

In the Azure portal it's presented like this.
When hovering on the text, the files icon appear.
When hovering the files icon, the tooltip shows-up.
image

@mathieu-fournier mathieu-fournier added the enhancement New feature or request label Feb 7, 2023
@mayank99
Copy link
Contributor

mayank99 commented Feb 7, 2023

Hey @mathieu-fournier, I do not think this necessarily belongs in iTwinUI, considering how easy it is to implement using Button, Tooltip and SvgCopy. I'm also not sure how the isCopyToClipboardEnabled prop would work. Where would it go? Could you elaborate, perhaps with some pseudocode?

@mayank99 mayank99 added the needs more info This issue is waiting on more info from author label Feb 7, 2023
@mathieu-fournier
Copy link
Author

I dont have the pseudo code yet.
I am planning to add this feature to my app soon tho, I'll make an update when it's done.

I think it's a feature that we could add to every component in Typography, except maybe Keyboard Key.
I am thinking about a boolean props like "is skeleton".
I think that behing easy to implement is a pros more than a cons., as it should be an easy feature to add. IsSkeleton is also kinda easy to implement and its still a feature that benefits a lot of applications. A low hanging fruit.

Example of how the props would work, it would be a boolean control props like isSkeleton.
When activated, the copy icon would appear when hovering, when inactive, nothing would happen. :
image

@mayank99
Copy link
Contributor

Typography components are a bit too level for this imo. Already not a fan of the isSkeleton prop because it feels unintuitive to use. The typography components are often used as inline elements (meaning display: inline) and can come in different sizes which may not scale 1:1 with an icon button sizes.

All that to say, a prop is not the right abstraction, and if we were to add this, it would likely be a new component.

I will leave this issue open, but in the meantime, here's a sandbox you can base your implementation on: codesandbox.io/s/copy-button-example-itwinui-pncqud (copy doesn't work in iframe, so preview in new window: https://pncqud.csb.app/)

@mayank99 mayank99 removed the needs more info This issue is waiting on more info from author label Feb 13, 2023
@mathieu-fournier
Copy link
Author

A prop would be awesome for usage simplicity, but I agree that it would definitely be more difficult to implement.
It would also have some limitations (like having control of the overflow behaviour).

I created a component that does the trick.
It needs some rework but it's good enough for my needs.
I made it that way, so the text overflows under the icon, when missing horizontal space.

https://codesandbox.io/s/copy-button-example-itwinui-forked-e96tz1?file=/src/CopyTextToClipboard.jsx
(copy doesn't work in iframe, so preview in new window: https://e96tz1.csb.app/)

@mayank99
Copy link
Contributor

One thing I should point out is that for better accessibility, you should consider using visually-hidden styles for hiding the button, and unhiding when hovered or focused. You can read more here: https://www.scottohara.me/blog/2017/04/14/inclusively-hidden.html

I've updated my sandbox to show how that would work:
https://codesandbox.io/s/copy-button-example-itwinui-pncqud?file=/src/App.jsx

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

No branches or pull requests

2 participants