New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onKeyDown
callback issue
#1444
Comments
What happened to this issue? how was it resolved? I'm experiencing the same where if the onKeyDown event is configured, it will end up getting executed on every key press regardless of being in the date picker or not. |
I also agree this should be reopened and fixed, this a huge problem and is not following good practice of separation of concerns. The fix should have been following what was written in this other issue #1387 and I also wrote the some concern in that issue
There's actually all these other events that are attached to the if (!self.config.inline && !self.config.static)
bind(window, "resize", debouncedResize);
if (window.ontouchstart !== undefined)
bind(window.document, "touchstart", documentClick);
else bind(window.document, "mousedown", documentClick);
bind(window.document, "focus", documentClick, { capture: true });
bind(self._input, "focus", self.open);
bind(self._input, "mousedown", self.open); Perhaps provide a way to disable the |
I have created PR #2329 to fix this since current code is causing too much performance downgrade (the more Flatpickr inputs we create, the more time it will re-execute the |
…#2329) * fix: restrict onKeyDown listener to Flatpickr only fixes #1444, #1387 - the current onKeyDown event is currently listening to `document.body` but that has major performance impact since that equals to listening to any keystroke coming from any DOM elements that exist in current body and it also adds this body event listener every single time a Flatpickr element is created (if you have 5x Flatpickr input, it will create the `onKeyDown` listener to the `document.body` 5x times and that is bad especiall for performance). - For a good separation of concerns, we should only listen to Flatpickr events coming from the Flatpickr input itself (or its calendar element) - this properly fixes issues #1387 and #1444 * refactor: use calendarContainer to listen to onKeyDown & fix unit tests Co-authored-by: Gregory <chmln@users.noreply.github.com>
Your Environment
JSFiddle
https://jsfiddle.net/p5tc0mg3/1/
Current behavior
onKeyDown
callback is being called on every key press from keyboardExpected behavior
The
onKeyDown
callback should be called only when flatpickr is doing something internally, for example, close on escape or set value on enter.Steps
onKeyDown
callback in config optionsonKeyDown
callback is being calledThe text was updated successfully, but these errors were encountered: