Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 9a36112

Browse files
kseamonThomasBurleson
authored andcommitted
fix(virtualRepeat): Do not scroll past bottom Fixes #6279 Might also fix #4169
Closes #6990
1 parent b683667 commit 9a36112

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/components/virtualRepeat/virtual-repeater.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,23 +346,23 @@ VirtualRepeatContainerController.prototype.resetScroll = function() {
346346

347347
VirtualRepeatContainerController.prototype.handleScroll_ = function() {
348348
var offset = this.isHorizontal() ? this.scroller.scrollLeft : this.scroller.scrollTop;
349-
if (offset === this.scrollOffset) return;
349+
if (offset === this.scrollOffset || offset > this.scrollSize - this.size) return;
350350

351351
var itemSize = this.repeater.getItemSize();
352352
if (!itemSize) return;
353353

354354
var numItems = Math.max(0, Math.floor(offset / itemSize) - NUM_EXTRA);
355355

356-
var transform = this.isHorizontal() ? 'translateX(' : 'translateY(';
357-
transform += (numItems * itemSize) + 'px)';
356+
var transform = (this.isHorizontal() ? 'translateX(' : 'translateY(') +
357+
(numItems * itemSize) + 'px)';
358358

359359
this.scrollOffset = offset;
360360
this.offsetter.style.webkitTransform = transform;
361361
this.offsetter.style.transform = transform;
362362

363363
if (this.bindTopIndex) {
364364
var topIndex = Math.floor(offset / itemSize);
365-
if (topIndex !== this.topIndex && topIndex < this.repeater.itemsLength) {
365+
if (topIndex !== this.topIndex && topIndex < this.repeater.getItemCount()) {
366366
this.topIndex = topIndex;
367367
this.bindTopIndex.assign(this.$scope, topIndex);
368368
if (!this.$rootScope.$$phase) this.$scope.$digest();
@@ -627,6 +627,15 @@ VirtualRepeatController.prototype.getItemSize = function() {
627627
};
628628

629629

630+
/**
631+
* Called by the container. Returns the size of a single repeated item.
632+
* @return {?number} Size of a repeated item.
633+
*/
634+
VirtualRepeatController.prototype.getItemCount = function() {
635+
return this.itemsLength;
636+
};
637+
638+
630639
/**
631640
* Updates the order and visible offset of repeated blocks in response to scrolling
632641
* or items updates.

src/components/virtualRepeat/virtual-repeater.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,21 @@ describe('<md-virtual-repeat>', function() {
616616
expect(offsetter.children().length).toBe(3);
617617
}));
618618

619+
it('should not scroll past the bottom', function() {
620+
scope.items = createItems(101);
621+
createRepeater();
622+
623+
scroller[0].scrollTop = ITEM_SIZE * 91;
624+
scroller.triggerHandler('scroll');
625+
626+
expect(getTransform(offsetter)).toBe('translateY(880px)');
627+
628+
scroller[0].scrollTop++;
629+
scroller.triggerHandler('scroll');
630+
631+
expect(getTransform(offsetter)).toBe('translateY(880px)');
632+
});
633+
619634
/**
620635
* Facade to access transform properly even when jQuery is used;
621636
* since jQuery's css function is obtaining the computed style (not wanted)

0 commit comments

Comments
 (0)