ui-select icon indicating copy to clipboard operation
ui-select copied to clipboard

Focus stealing

Open kikonen-fiksu opened this issue 12 years ago • 13 comments

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.

kikonen-fiksu avatar Oct 09 '14 18:10 kikonen-fiksu

I need some example to reproduce it and fix it. Can you create a plunker?

dimirc avatar Oct 09 '14 23:10 dimirc

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.

driver-by avatar Oct 15 '14 05:10 driver-by

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).

kikonen-fiksu avatar Oct 15 '14 06:10 kikonen-fiksu

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)

driver-by avatar Oct 15 '14 10:10 driver-by

Q: Is "$timeout" necessary, i.e. isn't it by definition possibly hitting race condition with fast enduser (like that "fast DOWN + ENTER" case).

kikonen-fiksu avatar Oct 15 '14 10:10 kikonen-fiksu

I think you are right. Timeout here is stealing focus back and hope it doesn't nessesary

driver-by avatar Oct 16 '14 05:10 driver-by

Nice find, this saved me lots of time thanks guys. Any idea how long until this fix will be in the latest build?

j-walker23 avatar Nov 24 '14 21:11 j-walker23

You're welcome, j-walker23! I want to find time to fix it properly ;)

driver-by avatar Nov 25 '14 06:11 driver-by

Find the time is the hardest part of life!

j-walker23 avatar Nov 25 '14 06:11 j-walker23

:+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?

BP18 avatar Jan 20 '15 23:01 BP18

We've also having this issue

ahendel avatar Jan 22 '15 16:01 ahendel

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

bettercallsteve avatar Feb 13 '15 15:02 bettercallsteve

This PR should fix it https://github.com/angular-ui/ui-select/pull/668

dimirc avatar Feb 16 '15 07:02 dimirc