Created
August 10, 2016 15:50
-
-
Save dcousineau/caa2ff6600ccf4ed824fa58c35be1cbb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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