Skip to content

Commit

Permalink
Merge pull request #4442 from wix/fix/type-on-email-input
Browse files Browse the repository at this point in the history
fix(iOS): avoid `setSelectionRange` on elements that don't support it
  • Loading branch information
asafkorem committed Apr 9, 2024
2 parents 3ed0623 + 4d495ae commit b5f94ca
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,21 @@ extension WebCodeBuilder {
}
};
if (document.activeElement !== element) {
element.focus();
}
if (typeof element.setSelectionRange === 'function') {
const length = getLength(element);
/* This is a workaround. See: https://w3.org/Bugs/Public/show_bug.cgi?id=24796 */
const originalType = element.getAttribute('type');
element.setAttribute('type', 'text');
if (element.nodeName.toLowerCase() === 'input' &&
['text', 'search', 'tel', 'url', 'password'].includes(element.type.toLowerCase()) === false) {
/* Some input types do not support `setSelectionRange`. See:
* https://html.spec.whatwg.org/multipage/input.html#:~:text=%C2%B7-,setSelectionRange(),-%C2%B7
*/
return;
}
const length = getLength(element);
element.setSelectionRange(length, length);
element.setAttribute('type', originalType);
} else {
var range = element.ownerDocument.createRange();
Expand Down

0 comments on commit b5f94ca

Please sign in to comment.