Skip to content
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

Beta 14: collection-repeat filter focus problem with $ionicScrollDelegate #2745

Closed
NoelLH opened this issue Dec 17, 2014 · 6 comments
Closed

Comments

@NoelLH
Copy link

NoelLH commented Dec 17, 2014

Beta 14 seems to have introduced a bug with collection-repeat.

My use case is very similar to the demo here except that I also want my large collection to scroll to the top of the list each time the filter text is changed, on the fly.

(As an aside, I think this might be better default behaviour? Without it, scrolling down a long list then filtering can mean that results are hidden from view off the top of the screen.)

I forked the collection-repeat demo codepen but had to remove most of the data since it appears to break on the actual Codepen site, as somebody has commented.

All I've changed from the demo is:

  • Ionic version
  • implemented $scope.scrollTop() - this was already referenced in an ng-change in the demo but just not in place

The function looks like

$scope.scrollTop = function() {
  $ionicScrollDelegate.scrollTop();
}

Here is it:

Expected/ working/ beta13 behaviour: list scrolls up but filter box keeps focus so you can keep typing.

Actual/ broken/ beta14 behaviour: the filter and scroll to top work, but the box loses focus, making it practically unusable for searches longer than 1 character.

@ffalcinelli
Copy link

Yup, I'm experiencing the exact same problem. Seems like $ionicScrollDelegate.scrollTop(); steals focus whereas in beta13 it was not acting in this way.

@dreamershl
Copy link

it is because now all the scrolling function add 1 more line "blurAll()". To avoid this issue, you can just getScrollView().scrollTo(0, 0, !!shouldAnimate).

self.scrollTop = function(shouldAnimate) {
   ionic.DomUtil.blurAll();
   self.resize().then(function() {
   scrollView.scrollTo(0, 0, !!shouldAnimate);
  });
};

@NoelLH
Copy link
Author

NoelLH commented Dec 20, 2014

Nice, thanks very much for that. I presume this side effect is still unintended for scrollTop(), but your suggestion looks like a solid workaround for my case.

@ffalcinelli
Copy link

Probably It's me, but I'm still losing focus when scrolling up. I'm invoking $ionicScrollDelegate.scrollTo(0, 0, false); and focus is lost.

Using $ionicScrollDelegate.getScrollView().scrollTo(0, 0, false); has no effect on the list.

What am I missing? Could you please update your codepen? I'd be very glad :)

@NoelLH
Copy link
Author

NoelLH commented Dec 20, 2014

It works for me with exactly that second line I'm afraid - jumps back to the top on change if you've scrolled down. Here's an updated codepen with the workaround: http://codepen.io/NoelLH/pen/EayGYd

It seems fine in my actual app where it's a bit more complicated too.

@ffalcinelli
Copy link

Ok, I found it. Just in case someone else has the same problem, I had to setup a delegate handle on my ion-content to make it work:

<ion-content delegate-handle="myScrollContent">
...
</ion-content>

Then in the controller:

$scope.scrollTop = function(){
    $ionicScrollDelegate.$getByHandle('myScrollContent').getScrollView().scrollTo(0, 0, true);
};

Hope this helps someone else!

@ajoslin ajoslin closed this as completed in 0145dc3 Feb 6, 2015
@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants