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:
commit
8688c2bc93
|
@ -31,10 +31,6 @@ type CopyBtnProps = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const CopyBtn = ({ content, increaseZindex = false }: CopyBtnProps) => {
|
const CopyBtn = ({ content, increaseZindex = false }: CopyBtnProps) => {
|
||||||
if (!navigator.clipboard) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
const [clicked, setClicked] = useState<boolean>(false)
|
const [clicked, setClicked] = useState<boolean>(false)
|
||||||
const classes = useStyles()
|
const classes = useStyles()
|
||||||
const customClasses = increaseZindex ? { popper: classes.inreasedPopperZindex } : {}
|
const customClasses = increaseZindex ? { popper: classes.inreasedPopperZindex } : {}
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
export const copyToClipboard = (text: string) => {
|
export const copyToClipboard = (text: string): void => {
|
||||||
if (!navigator.clipboard) {
|
const range = document.createRange()
|
||||||
return
|
range.selectNodeContents(document.body)
|
||||||
}
|
document.getSelection().addRange(range)
|
||||||
|
|
||||||
try {
|
function listener(e: ClipboardEvent) {
|
||||||
navigator.clipboard.writeText(text)
|
e.clipboardData.setData('text/plain', text)
|
||||||
} catch (err) {
|
e.preventDefault()
|
||||||
console.error(err.message)
|
|
||||||
}
|
}
|
||||||
|
document.addEventListener('copy', listener)
|
||||||
|
document.execCommand('copy')
|
||||||
|
document.removeEventListener('copy', listener)
|
||||||
|
|
||||||
|
document.getSelection().removeAllRanges()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue