forked from pmndrs/zustand
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(example): updated with the latest version of the clipboard A…
…PI (pmndrs#1072) * refactor: updated with the latest version of the clipboard API in example zustand * Update examples/src/utils/copy-to-clipboard.js Co-authored-by: Daishi Kato <[email protected]>
- Loading branch information
Showing
2 changed files
with
7 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,3 @@ | ||
export const copyToClipboard = (str) => { | ||
const el = document.createElement('textarea') | ||
el.value = str | ||
el.setAttribute('readonly', '') | ||
el.style.position = 'absolute' | ||
el.style.left = '-9999px' | ||
document.body.appendChild(el) | ||
el.select() | ||
// FIXME: might need to update this with the clipboard API in the future | ||
document.execCommand('copy') | ||
document.body.removeChild(el) | ||
} | ||
return navigator.clipboard.writeText(str) | ||
} |