Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Disallow using setSelectionRange on number inputs. This fixes #555. #558

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/fastclick.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,11 @@
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') {
var disallowedTypes = ['time', 'month', 'email', 'number'];
if (deviceIsIOS &&
targetElement.setSelectionRange &&
targetElement.type.indexOf('date') !== 0 &&
disallowedTypes.indexOf(targetElement.type) === -1) {
length = targetElement.value.length;
targetElement.setSelectionRange(length, length);
} else {
Expand Down