Skip to content

Instantly share code, notes, and snippets.

@dcousineau
Created August 10, 2016 15:50
Show Gist options
  • Save dcousineau/caa2ff6600ccf4ed824fa58c35be1cbb to your computer and use it in GitHub Desktop.
Save dcousineau/caa2ff6600ccf4ed824fa58c35be1cbb to your computer and use it in GitHub Desktop.
// Autofill in iOS Chrome doesn't trigger a change or input event, so React
// doesn't know to update the props with the autofilled value. the props still
// have the pre-autofilled value of the input, and things break. This polyfill
// is based off of a Chrome-iOS JQuery/Angular specific fix:
// https://github.com/tbosch/autofill-event/blob/master/src/autofill-event.js
if (navigator.userAgent.match(`CriOS`)) {
const triggerInputEvent = element => {
const event = new Event(`input`, {bubbles: true});
element.dispatchEvent(event);
};
const blurListener = event => {
const {target} = event;
if (target.type === `email` && target.nodeName === `INPUT`) {
setTimeout(() => triggerInputEvent(target), 20);
}
};
document.addEventListener(`blur`, blurListener, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment