From 56cf6cc9e95bdc72db1b6007dc6d243c087f945a Mon Sep 17 00:00:00 2001 From: wooglie Date: Thu, 2 May 2019 14:02:03 +0200 Subject: [PATCH] Issue #160: Added targetElement type number to check Error: `Uncaught DOMException: Failed to execute 'setSelectionRange' on 'HTMLInputElement': The input element's type ('number') does not support selection.` Affected: iPhones and iPads Input types: date, time, month, email, number --- lib/fastclick.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/fastclick.js b/lib/fastclick.js index 225ff660..b6d48edc 100644 --- a/lib/fastclick.js +++ b/lib/fastclick.js @@ -326,12 +326,13 @@ var length; // Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724. - if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month' && targetElement.type !== 'email') { + if (deviceIsIOS && targetElement.setSelectionRange && !['date', 'time', 'month', 'email', 'number'].includes(targetElement.type)) { length = targetElement.value.length; targetElement.setSelectionRange(length, length); } else { targetElement.focus(); } + targetElement.focus(); };