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

Commit cff2654

Browse files
committed
fix(virtualRepeat): Recover from scroll events that occur when hidden
Fixes #5448. comment
1 parent 2eaf210 commit cff2654

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/components/virtualRepeat/virtual-repeater.js

+5
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ VirtualRepeatContainerController.prototype.updateSize = function() {
197197
? this.$element[0].clientWidth
198198
: this.$element[0].clientHeight;
199199

200+
// Recheck the scroll position after updating the size. This resolves
201+
// problems that can result if the scroll position was measured while the
202+
// element was display: none or detached from the document.
203+
this.handleScroll_();
204+
200205
this.repeater && this.repeater.containerUpdated();
201206
};
202207

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

+11-3
Original file line numberDiff line numberDiff line change
@@ -580,17 +580,25 @@ describe('<md-virtual-repeat>', function() {
580580
expect(offsetter.children().length).toBe(43);
581581
});
582582

583-
it('should recheck container size on $md-resize scope event', function() {
583+
it('should recheck container size and scroll position on $md-resize scope ' +
584+
'event', function() {
584585
scope.items = createItems(100);
585586
createRepeater();
586587
// Expect 13 children (10 + 3 extra).
587588
expect(offsetter.children().length).toBe(13);
588589

590+
container.css('height', '300px');
591+
scope.$parent.$broadcast('$md-resize');
592+
593+
// Expect 33 children (30 + 3 extra).
594+
expect(offsetter.children().length).toBe(33);
595+
589596
container.css('height', '400px');
597+
scroller[0].scrollTop = 20;
590598
scope.$parent.$broadcast('$md-resize');
591599

592-
// Expect 43 children (40 + 3 extra).
593-
expect(offsetter.children().length).toBe(43);
600+
// Expect 43 children (40 + 5 extra).
601+
expect(offsetter.children().length).toBe(45);
594602
});
595603

596604
it('should shrink when initial results require shrinking', inject(function() {

0 commit comments

Comments
 (0)