Apply logic only when target is an input element

This commit is contained in:
Beto Muniz 2022-05-03 13:21:15 -03:00
parent abfb43cdb5
commit ca882fd16f
4 changed files with 6 additions and 5 deletions

2
dist/clipboard.js vendored
View File

@ -125,7 +125,7 @@ var ClipboardActionCopy = function ClipboardActionCopy(target) {
if (typeof target === 'string') {
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
selectedText = fakeCopyAction(target.value, options);
} else {

File diff suppressed because one or more lines are too long

View File

@ -32,6 +32,7 @@ const ClipboardActionCopy = (
if (typeof target === 'string') {
selectedText = fakeCopyAction(target, options);
} else if (
target instanceof HTMLInputElement &&
!['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

View File

@ -54,10 +54,10 @@ describe('ClipboardActionCopy', () => {
it('should select its value in a input number based on text', () => {
const value = 1;
document.querySelector('input').setAttribute('type', 'number');
document.querySelector('input').setAttribute('value', value);
document.querySelector('#input').setAttribute('type', 'number');
document.querySelector('#input').setAttribute('value', value);
const selectedText = ClipboardActionCopy(
document.querySelector('input'),
document.querySelector('#input'),
{
container: document.body,
}