Focus stealing
In some case selector widgets may stuck into "focus stealing" mode. I.e. When trying to select another field in form (with mouse) ui-select field keeps stealing focus back (so attempt to select another field and type text there ends up typing in ui-select field).
Noticed with bootstrap theme, didn't yet figure steps required to trigger bug.
I need some example to reproduce it and fix it. Can you create a plunker?
If I understand correctly, the issue is common. Just see it here: ui-select demo page. Click on first select, than on second and type any letter. You will see that the focus is steal on the first select input.
thx, I can confirm that that sample contains focus stealing, which looks similar than what I noticed elsewhere.
Actually I have feeling that this same issue could explain also peculiarities what I noticed in tabulation; occasional erratic behavior in ui-select fields (for example, sometimes focus not moving to next field).
The problem is here:
// Closes the dropdown
ctrl.close = function(skipFocusser) {
if (!ctrl.open) return;
_resetSearchInput();
ctrl.open = false;
if (!ctrl.multiple){
$timeout(function(){
ctrl.focusser.prop('disabled', false);
if (!skipFocusser) ctrl.focusser[0].focus();// <-- Comment this line to avoid focus stealing
},0,false);
}
};
I don't know the concept of focusser, so I can't fix it correctly (I assume this line is needed in other code)
Q: Is "$timeout" necessary, i.e. isn't it by definition possibly hitting race condition with fast enduser (like that "fast DOWN + ENTER" case).
I think you are right. Timeout here is stealing focus back and hope it doesn't nessesary
Nice find, this saved me lots of time thanks guys. Any idea how long until this fix will be in the latest build?
You're welcome, j-walker23! I want to find time to fix it properly ;)
Find the time is the hardest part of life!
:+1: Would love to see a fix for this!
Related to #253?
Fix from driver-by above doesn't seem to work with latest ui-select versions?
We've also having this issue
Temp fixed by changing:
$select.close(angular.element(e.target).closest('.ui-select-container.open').length > 0);
To:
$select.close(e.target.tagName.toUpperCase() == 'INPUT' || angular.element(e.target).closest('.ui-select-container.open').length > 0);
Could be expanded to support textarea and/or contenteditable, too
This PR should fix it https://github.com/angular-ui/ui-select/pull/668