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
Duplicate or wrong event binding (keydown) #1387
Comments
This should be reopen and should have been followed according to the original proposition, the current
|
…#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
It seems like there is a duplicate or wrong event binding.
The
keydown
event is falsely bound to thewindow.document.body
:flatpickr/src/index.ts
Line 412 in 91756bb
but the correct binding to the input field is already set at the next line:
flatpickr/src/index.ts
Line 414 in 91756bb
This results in firing the
onKeyDown
function on every keypress at the whole page.A simple removing
line 412
should prevent the keydown-event-firework if multiple instances of the picker are used at a time.Expected
Firing the
keydown
event only if the flatpickr has focus.Observed
Firing the
keydown
on every keypress at the whole page. Numerous if multiple pickers are used.Solution
Removing
line 412
atflatpickr/src/index.ts
The text was updated successfully, but these errors were encountered: