Skip to content

Commit f9a4833

Browse files
authored
Merge pull request #27 from github/input
Use copyText to copy input value
2 parents e505506 + a3b00f4 commit f9a4833

File tree

2 files changed

+2
-22
lines changed

2 files changed

+2
-22
lines changed

src/clipboard-copy-element.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow strict */
22

3-
import {copyInput, copyNode, copyText} from './clipboard'
3+
import {copyNode, copyText} from './clipboard'
44

55
function copy(button: HTMLElement) {
66
const id = button.getAttribute('for')
@@ -22,11 +22,7 @@ function copy(button: HTMLElement) {
2222

2323
function copyTarget(content: Element) {
2424
if (content instanceof HTMLInputElement || content instanceof HTMLTextAreaElement) {
25-
if (content.type === 'hidden') {
26-
return copyText(content.value)
27-
} else {
28-
return copyInput(content)
29-
}
25+
return copyText(content.value)
3026
} else if (content instanceof HTMLAnchorElement && content.hasAttribute('href')) {
3127
return copyText(content.href)
3228
} else {

src/clipboard.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,3 @@ export function copyText(text: string): Promise<void> {
5151
body.removeChild(node)
5252
return Promise.resolve()
5353
}
54-
55-
export function copyInput(node: HTMLInputElement | HTMLTextAreaElement): Promise<void> {
56-
if ('clipboard' in navigator) {
57-
// eslint-disable-next-line flowtype/no-flow-fix-me-comments
58-
// $FlowFixMe Clipboard is not defined in Flow yet.
59-
return navigator.clipboard.writeText(node.value)
60-
}
61-
62-
node.select()
63-
document.execCommand('copy')
64-
const selection = getSelection()
65-
if (selection != null) {
66-
selection.removeAllRanges()
67-
}
68-
return Promise.resolve()
69-
}

0 commit comments

Comments
 (0)