Skip to content

Instantly share code, notes, and snippets.

@sajjadanwar0
Forked from ntzm/fix.js
Created November 19, 2024 23:24
Show Gist options
  • Save sajjadanwar0/40bd8603688ef42806bea5ef3a936b92 to your computer and use it in GitHub Desktop.
Save sajjadanwar0/40bd8603688ef42806bea5ef3a936b92 to your computer and use it in GitHub Desktop.
// 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