Closed FlowIT-JIT closed 2 years ago
This bug is related to two issues:
First issue:
https://github.com/Jemt/Fit.UI/blob/780b41ff958cff45d8e8f41f39bb0612f6799e2d/Controls/TreeView/TreeView.js#L374
This code will cause focus to be moved back to DropDown's input field when an item is selected using click/touch in the picker control (TreeView). It was only intended to invoke FireOnFocusIn if the control was to lose focus to an outer container with tabIndex set. The browser will move focus to an element further up the DOM hierarchy when interacting with the scrollbar, if the parent is focusable. But due to the bug on line 391, FireOnFocusIn is always invoked.
But we also invoke FireOnFocusIn when TreeView gains focus in general, which happens when clicking an item:
https://github.com/Jemt/Fit.UI/blob/780b41ff958cff45d8e8f41f39bb0612f6799e2d/Controls/TreeView/TreeView.js#L1282
So FireOnFocusIn gets invoked twice. This in turn results in onFocusIn and onFocusOut in ControlBase being invoked like in/out/out/in/in, rather than in/out/in/out/in as expected, and this results in two blur timers being scheduled to execute in onFocusOut, which is exactly what is causing the problem. When onFocusIn fires, it cancels any onBlur timer set. But if onFocusOut fires multiple times, prior onBlur timers are not canceled:
https://github.com/Jemt/Fit.UI/blob/780b41ff958cff45d8e8f41f39bb0612f6799e2d/Core/ControlBase.js#L1134
Second issue: The second issue is touched upon in the last code reference above - the onFocusIn and OnFocusOut handlers in ControlBase. They only work as expected if they are fired in turn - like in/out/in/out rather than in/out/out/in/in. The following example demonstrates the problem using pure JavaScript: https://codepen.io/JemtDK/pen/abqRqNy?editors=0010 Can we make it more robust by canceling the onBlur timer in the onFocusOut handler, if it is already scheduled for execution?
Both issues mentioned have now been fixed.
Consider the following example (code also attached below): https://jsfiddle.net/34q5n7xm/8/ EDIT: JSFiddle no longer triggers the bug since it runs on the most recent (and now fixed) version of Fit.UI! To reproduce the bug, Fit.UI version 2.11.7 or earlier is required!
1) Open the dropdown control 2) Scroll the content by dragging the scrollbar (do not use scroll wheel!) 3) Select an item
Notice how OnBlur fires - this is not supposed to happen!