flynt
flynt copied to clipboard
Fixing use of `execCommand('copy')`
When using the Copy Link button on the Anchor component without navigator.clipboard
support, it reverts to execCommand('copy')
which requires the content to copy to be selected.
This PR adds code to ensure the link is selected before calling execCommand('copy')
.
@gRoberts84 many thanks for the pr. I took a short to can i use: https://caniuse.com/?search=navigator.clipboard
It seems that navigator.clipboard
has widely support (95.37%; [04-26-2024]) which is pretty close to the the browserlist
setting supports array-flat (96.82%; [04-26-2024]) inside the package.json.
Did you run in trouble with the current implementation at a specific browser? I am looking forward to learning more details.
Hi @timohubois
Apologies for the delay in getting back to you.
I had mistaken it only working over HTTPS as a bug but it had highlighted an issue where if navigator.clipboard
isn't available for any reason (e.g. insecure local environment) then it tries to use execCommand('copy')
without any text being selected, so it copies nothing.
Appreciate that under most circumstances, this won't be an issue but someone could come across it again on an insecure site.
@gRoberts84 many thanks for your feedback.
I think it's not a problem or a bug as this is the normal behavior of the "Navigator: clipboard property" and insecure connections are rather uncommon and an edge case these days in my opinion.
Would prefer to close this issue in relation to this. What do you think?
@timohubois appreciate your view on this and happy to close the PR.