mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Apply logic only when target is an input element
This commit is contained in:
2
dist/clipboard.js
vendored
2
dist/clipboard.js
vendored
@@ -125,7 +125,7 @@ var ClipboardActionCopy = function ClipboardActionCopy(target) {
|
|||||||
|
|
||||||
if (typeof target === 'string') {
|
if (typeof target === 'string') {
|
||||||
selectedText = fakeCopyAction(target, options);
|
selectedText = fakeCopyAction(target, options);
|
||||||
} else if (!['text', 'search', 'url', 'tel', 'password'].includes(target === null || target === void 0 ? void 0 : target.type)) {
|
} else if (target instanceof HTMLInputElement && !['text', 'search', 'url', 'tel', 'password'].includes(target === null || target === void 0 ? void 0 : target.type)) {
|
||||||
// If input type doesn't support `setSelectionRange`. Simulate it. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange
|
// If input type doesn't support `setSelectionRange`. Simulate it. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange
|
||||||
selectedText = fakeCopyAction(target.value, options);
|
selectedText = fakeCopyAction(target.value, options);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
2
dist/clipboard.min.js
vendored
2
dist/clipboard.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -32,6 +32,7 @@ const ClipboardActionCopy = (
|
|||||||
if (typeof target === 'string') {
|
if (typeof target === 'string') {
|
||||||
selectedText = fakeCopyAction(target, options);
|
selectedText = fakeCopyAction(target, options);
|
||||||
} else if (
|
} else if (
|
||||||
|
target instanceof HTMLInputElement &&
|
||||||
!['text', 'search', 'url', 'tel', 'password'].includes(target?.type)
|
!['text', 'search', 'url', 'tel', 'password'].includes(target?.type)
|
||||||
) {
|
) {
|
||||||
// If input type doesn't support `setSelectionRange`. Simulate it. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange
|
// If input type doesn't support `setSelectionRange`. Simulate it. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange
|
||||||
|
|||||||
@@ -54,10 +54,10 @@ describe('ClipboardActionCopy', () => {
|
|||||||
|
|
||||||
it('should select its value in a input number based on text', () => {
|
it('should select its value in a input number based on text', () => {
|
||||||
const value = 1;
|
const value = 1;
|
||||||
document.querySelector('input').setAttribute('type', 'number');
|
document.querySelector('#input').setAttribute('type', 'number');
|
||||||
document.querySelector('input').setAttribute('value', value);
|
document.querySelector('#input').setAttribute('value', value);
|
||||||
const selectedText = ClipboardActionCopy(
|
const selectedText = ClipboardActionCopy(
|
||||||
document.querySelector('input'),
|
document.querySelector('#input'),
|
||||||
{
|
{
|
||||||
container: document.body,
|
container: document.body,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user