Inconsistency in scrollNext and scrollPrev
Description
There are inconsistencies in scrollNext and scrollPrev
- Inconsistency in cyclic scrolling: scrollNext scrolls back to the top when the scroll position is at the bottom. On the other hand, scrollPrev does not scroll to the bottom when the scroll position is at the top.
- Inconsistency in behaviors between an old version (ex. 6.1.3) and 7.0.1: scrollNext and scrollPrev stops scrolling when the scroll position comes to the bottom or the top in 6.1.3. On the other hand, in 7.0.1, scrollNext scrolls to the top when the scroll position is at the bottom.
- Inconsistency in scroll position between contents and the scroll bar thumb: The scroll bar thumb goes to the top position if scrollNext is called when the scroll position is at the bottom. On the other hand, the contents does not go to the top.
- igniteui-angular version: 7.0.1
- browser: any
Steps to reproduce
- npm install and npm start the attached sample. Open it in a browser.
- Click "Down" button several times until "14: Name 14" the last item comes into view.
- Click "Down" button again. -> Observe the positions of the scroll bar's thumb and the contents.
- Click "Down" button again. -> The scroll positions of the scroll bar's thumb and the contents get aligned again.
- Click "Up" button several times. -> Observe whether it scrolls to the bottom when the scroll position is at the top.
Result
Step3: The scroll bar's thumb is at the top, but the items at the bottom are still displayed.
Step5: The igx-list does not scroll to the bottom.
Expected result
The behaviors should be consistent. That is:
- If scrollNext's cyclic scrolling is an expected behavior, scrollPrev should also cyclicly scroll. Or if scrollPrev's non-cyclic scrolling is an expected behavior, scrollNext should not cyclicly scroll (Step5).
- Contents and scroll bar's thumb positions should be aligned (Step3).
Attachments
Attach a sample if available, and screenshots, if applicable.
cas30409-app1.zip
https://github.com/IgniteUI/igniteui-angular/blob/master/projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts#L427-L430
public scrollTo(index) {
if (index < 0 || index > (this.isRemote ? this.totalItemCount : this.igxForOf.length)) {
return;
}
In the first place, it seems that this guard clause doesn't work as expected.
When "this.igxForOf.length" is 15, the index range is 0 - 14. But, if 15 is passed to scrollTo(), the program passes through the guard statement. As a result, this.sizesCache[index + 1] returns undefined and calculation fails.
The guard statement should be fixed like this.
public scrollTo(index) {
const lastIndex = (this.isRemote ? this.totalItemCount : this.igxForOf.length) - 1;
if (index < 0 || lastIndex < index) {
return;
}
Any updates?
We haven't had a chance to investigate it.
@tkiryu What you suggest looks correct. You can make a PR, but don't forget to include a test as well :)
@tkiryu I've communicated this issue with Satoru Yamaguchi. As he is escalating it we will take care of it.
@mpavlinov , thank you so much!