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

fix(virtualRepeat): Recover from scroll events that occur when hidden #6389

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/components/virtualRepeat/virtual-repeater.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ VirtualRepeatContainerController.prototype.updateSize = function() {
? this.$element[0].clientWidth
: this.$element[0].clientHeight;

// Recheck the scroll position after updating the size. This resolves
// problems that can result if the scroll position was measured while the
// element was display: none or detached from the document.
this.handleScroll_();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment as to why you're calling the scroll handler here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


this.repeater && this.repeater.containerUpdated();
};

Expand Down
14 changes: 11 additions & 3 deletions src/components/virtualRepeat/virtual-repeater.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,17 +580,25 @@ describe('<md-virtual-repeat>', function() {
expect(offsetter.children().length).toBe(43);
});

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

container.css('height', '300px');
scope.$parent.$broadcast('$md-resize');

// Expect 33 children (30 + 3 extra).
expect(offsetter.children().length).toBe(33);

container.css('height', '400px');
scroller[0].scrollTop = 20;
scope.$parent.$broadcast('$md-resize');

// Expect 43 children (40 + 3 extra).
expect(offsetter.children().length).toBe(43);
// Expect 43 children (40 + 5 extra).
expect(offsetter.children().length).toBe(45);
});

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