-
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.
Merge pull request #29 from TEAM-WHEN-WILL-WE-MEET/develop
[FIX] Web Share API 버그 픽스
- Loading branch information
Showing
16 changed files
with
477 additions
and
82 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
const getDummyTextarea = () => { | ||
const textarea = document.createElement("textarea") as HTMLTextAreaElement; | ||
textarea.style.top = "0"; | ||
textarea.style.left = "0"; | ||
textarea.style.display = "fixed"; | ||
|
||
return textarea; | ||
}; | ||
|
||
export const isClipboardSupported = () => navigator?.clipboard != null; | ||
export const isClipboardCommandSupported = () => | ||
document.queryCommandSupported?.("copy") ?? false; | ||
|
||
/** | ||
* 인자로 받은 텍스트를 클립보드에 복사합니다. | ||
* @param text 복사할 텍스트 | ||
* | ||
* @example | ||
* ```ts | ||
* const result = await copyToClipboard('하이'); | ||
* if (result) { | ||
* console.log('클립보드에 복사 성공'); | ||
* } else { | ||
* console.log('클립보드에 복사 실패'); | ||
* } | ||
* ``` | ||
*/ | ||
export const copyToClipboard = (text: string) => { | ||
return new Promise<boolean>(async (resolve) => { | ||
const rootElement = document.body; | ||
|
||
// if (isClipboardSupported()) { | ||
// await navigator.clipboard.writeText(text); | ||
// resolve(true); | ||
// return; | ||
// } | ||
|
||
if (isClipboardCommandSupported()) { | ||
const textarea = getDummyTextarea(); | ||
textarea.value = text; | ||
|
||
rootElement.appendChild(textarea); | ||
|
||
textarea.focus(); | ||
textarea.select(); | ||
|
||
document.execCommand("copy"); | ||
rootElement.removeChild(textarea); | ||
resolve(true); | ||
return; | ||
} | ||
|
||
resolve(false); | ||
return; | ||
}); | ||
}; | ||
|
||
export default copyToClipboard; |
Oops, something went wrong.