Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

weird behavior in iOS Safari #603

Open
jesuslpm opened this issue Jan 22, 2015 · 16 comments
Open

weird behavior in iOS Safari #603

jesuslpm opened this issue Jan 22, 2015 · 16 comments

Comments

@jesuslpm
Copy link

Hello,

ui-select works great on desktop, but in iOS Safare I have experienced weird behavior. When you clik on the control some ramdom item is selected, the keyboard is not shown. If then you select one item tapping on it, the keyboard is suddenly shown and the wrong item is selected. If instead of tapping on an item, you tap on the control again, the keyboard is shown, and all works as expected.

@jesuslpm
Copy link
Author

You can see this behavior on the demo page, testing it with iPad mini iOs version 8.1.2

http://plnkr.co/edit/a3KlK8dKH3wwiiksDSn2?p=preview

@aziule
Copy link

aziule commented Feb 13, 2015

Same issue here on iPad mini 2 & iPhone 4/4S

@siva-I
Copy link

siva-I commented Feb 25, 2015

Is there a fix for this issue yet? i am also facing this issue.

@sinxwal
Copy link

sinxwal commented Mar 16, 2015

+1

2 similar comments
@MalikAbed
Copy link

+1

@dallasclark
Copy link

+1

@tallsam
Copy link

tallsam commented Apr 24, 2015

can confirm this too

@aziule
Copy link

aziule commented Apr 27, 2015

Have somebody found how to fix it? Any forked project / quickfix?

@trouseredApe
Copy link

+1

@driver-by
Copy link

The reason of the bug is that iOS safari doesn't allow to set focus from functions which wasn't the result of user's interaction. Specifically the first function in call stack must be some sort of reaction on 'click', 'touchend',.. events. Some details here.
Quick fix is to remove timeout in this code:
Replace

$timeout(function() {
  ctrl.search = initSearchValue || ctrl.search;
  ctrl.searchInput[0].focus();
});

with

  ctrl.search = initSearchValue || ctrl.search;
  ctrl.searchInput[0].focus();

Timeout starts new function call stack, so iOs Safari doesn't allow that .focus().
But, important! This code won't work, if your input is hidden with display: none (or some of it ancestors). You can't set focus to the hidden element.
That's why this timeout is here - it waits when angular shows the dropdown.
I use select2 theme, so I updated my styles with:

.select2-display-none {
  overflow: hidden;
  height: 0;
  opacity: 0;
}

Also I recommend to disable focusser activation on select close, to prevent iOS keyboard jumping. Here is the code of close function. My code is:

ctrl.close = function() {
    if (!ctrl.open) return;
    if (ctrl.ngModel && ctrl.ngModel.$setTouched) ctrl.ngModel.$setTouched();
    _resetSearchInput();
    ctrl.open = false;

    $scope.$broadcast('uis:close', true);

  };

Conclusion
I don't know how to fix that properly in ui-select, but one of the approaches is to replace the timeout in first piece of code and show dropdowns not by angular class, but with immediate style update before focus (remove 'display: none').
About jumping keyboard on close... I don't know why skipFocusser is in the close function, so cannot suggest how to prevent skpFocusser === false for iOS here.

@hjmodha
Copy link

hjmodha commented May 26, 2015

+1

5 similar comments
@ahuang321
Copy link

+1

@madmed88
Copy link

+1

@amrsh
Copy link

amrsh commented Sep 3, 2015

+1

@adolfov
Copy link

adolfov commented Nov 3, 2015

+1

@AlemaoEc
Copy link

+1

aaronroberson added a commit that referenced this issue Mar 15, 2016
feat(skipFocuser): add skip focusser option

Add a skipFocusser option to configure skipping the focusser after selecting an item.

Closes #869 #401 #818 #603 #432
bsouthga added a commit to CrossLead/ui-select that referenced this issue Jul 7, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests