Skip to content

Commit

Permalink
fix: add iOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobad committed Jul 18, 2019
1 parent 8f65068 commit 7ae79d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
14 changes: 0 additions & 14 deletions src/detect-autofill.css

This file was deleted.

16 changes: 6 additions & 10 deletions src/detect-autofill.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
try {
// watch onanimationstart for -webkit browsers
document.querySelector(':-webkit-autofill');
document.addEventListener('animationstart', onAnimationStart);
} catch (e) {
// watch oninput for non-webkit browsers
document.addEventListener('input', onInput, true);
}
import './detect-autofill.scss';

document.addEventListener('animationstart', onAnimationStart, true);
document.addEventListener('input', onInput, true);

// polyfill CustomEvent for < IE11
if (typeof window.CustomEvent !== 'function') {
Expand Down Expand Up @@ -65,7 +61,7 @@ function autocomplete(element) {
if (element.hasAttribute('autocompleted')) return;
element.setAttribute('autocompleted', '');

var event = new CustomEvent('onautocomplete', {
var event = new window.CustomEvent('onautocomplete', {
bubbles: true, cancelable: true, detail: null,
});

Expand All @@ -89,7 +85,7 @@ function cancelAutocomplete(element) {
element.removeAttribute('autocompleted');

// dispatch event
element.dispatchEvent(new CustomEvent('onautocomplete', {
element.dispatchEvent(new window.CustomEvent('onautocomplete', {
bubbles: true, cancelable: false, detail: null,
}));
}
12 changes: 12 additions & 0 deletions src/detect-autofill.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
INPUT, SELECT, TEXTAREA {
&:-webkit-autofill {
animation-name: onautofillstart;
}

&:not(:-webkit-autofill) {
animation-name: onautofillcancel;
}
}

@keyframes onautofillstart { from {} }
@keyframes onautofillcancel { from {} }

0 comments on commit 7ae79d4

Please sign in to comment.