Merge pull request #270 from gnosis/bug/safari-clipboard-btns

Bug #234: Click to copy buttons are not shown in safari
This commit is contained in:
Mikhail Mikheev 2019-11-18 11:04:47 +04:00 committed by GitHub
commit 8688c2bc93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 12 deletions

View File

@ -31,10 +31,6 @@ type CopyBtnProps = {
}
const CopyBtn = ({ content, increaseZindex = false }: CopyBtnProps) => {
if (!navigator.clipboard) {
return null
}
const [clicked, setClicked] = useState<boolean>(false)
const classes = useStyles()
const customClasses = increaseZindex ? { popper: classes.inreasedPopperZindex } : {}

View File

@ -1,13 +1,17 @@
// @flow
export const copyToClipboard = (text: string) => {
if (!navigator.clipboard) {
return
}
export const copyToClipboard = (text: string): void => {
const range = document.createRange()
range.selectNodeContents(document.body)
document.getSelection().addRange(range)
try {
navigator.clipboard.writeText(text)
} catch (err) {
console.error(err.message)
function listener(e: ClipboardEvent) {
e.clipboardData.setData('text/plain', text)
e.preventDefault()
}
document.addEventListener('copy', listener)
document.execCommand('copy')
document.removeEventListener('copy', listener)
document.getSelection().removeAllRanges()
}