Skip to content

Commit

Permalink
fix(ui): copyToClipboard fallback mechanism in dialog #15076
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Jan 11, 2023
1 parent 39f7305 commit 6b363e1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ui/src/utils/copy-to-clipboard.js
@@ -1,16 +1,24 @@

import { addFocusout, removeFocusout } from './private/focusout.js'

function fallback (text) {
const area = document.createElement('textarea')
area.value = text
area.contentEditable = 'true'
area.style.position = 'fixed' // avoid scrolling to bottom

const fn = () => {}
addFocusout(fn)

document.body.appendChild(area)
area.focus()
area.select()

const res = document.execCommand('copy')

area.remove()
removeFocusout(fn)

return res
}

Expand Down

0 comments on commit 6b363e1

Please sign in to comment.