Created
August 1, 2019 11:20
-
-
Save ntzm/1a5ff006e473db2937fc0cabf573ce1b to your computer and use it in GitHub Desktop.
This file contains 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
// Fix for Firefox | |
// Can be removed after release with this patch in: https://github.com/flatpickr/flatpickr/pull/1879 | |
const brokenInputs = [ | |
input._flatpickr.hourElement, | |
input._flatpickr.minuteElement, | |
]; | |
brokenInputs.forEach(input => { | |
input.addEventListener('input', e => { | |
// Date isn't updated if you close the popup without pressing enter on Firefox, we can resolve this by blurring | |
// then focusing straight away | |
e.target.blur(); | |
e.target.focus(); | |
// After we've given focus back, it selects the whole input, so if the user types in anything it overwrites what's | |
// already there. We can force the browser to put the cursor at the end of the input by clearing and re-filling | |
// the value | |
const { value } = e.target; | |
e.target.value = ''; | |
e.target.value = value; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment