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

Prevent scrollEvent when scroll percentage is greater then 1. #6241

Merged
merged 4 commits into from
Jun 18, 2017
Merged
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
8 changes: 6 additions & 2 deletions src/js/core/factories/Grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,9 @@ angular.module('ui.grid')

// Turn the scroll position into a percentage and make it an argument for a scroll event
percentage = scrollPixels / scrollLength;
scrollEvent.y = { percentage: percentage };
if (percentage <= 1) {
scrollEvent.y = { percentage: percentage };
}
}
// Otherwise if the scroll position we need to see the row is MORE than the bottom boundary, i.e. obscured below the bottom of the self...
else if (pixelsToSeeRow > bottomBound) {
Expand All @@ -2404,7 +2406,9 @@ angular.module('ui.grid')

// Turn the scroll position into a percentage and make it an argument for a scroll event
percentage = scrollPixels / scrollLength;
scrollEvent.y = { percentage: percentage };
if (percentage <= 1) {
scrollEvent.y = { percentage: percentage };
}
}
}

Expand Down
64 changes: 64 additions & 0 deletions test/unit/core/factories/Grid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,70 @@ describe('Grid factory', function () {
$scope.$digest();
}

describe('scrollToIfNecessary', function() {
var renderContainers;
var prevScrollTop = 100;
var viewportWidth = 100;
var viewportHeight = 100;
var canvasHeight = 360;
var canvasWidth = 100;

beforeEach(function() {
renderContainers = {
body: {
visibleRowCache: null,
visibleColumnCache: null,
prevScrollTop: prevScrollTop,
headerHeight: 30,
getViewportWidth: jasmine.createSpy('getViewportWidth').and.callFake(function() { return viewportWidth;}),
getViewportHeight: jasmine.createSpy('getViewportWidth').and.callFake(function() { return viewportHeight;}),
getCanvasHeight: jasmine.createSpy('getCanvasHeight').and.callFake(function() { return canvasHeight; }),
getCanvasWidth: jasmine.createSpy('getCanvasHeight').and.callFake(function() { return canvasWidth; })
}
};
});

it('should not scroll.y when scrollpercentage > 100% when row is less then top boundry', function() {
// row is less then the top boundary
var rowCache = [];
for ( var i = 0; i < 9; i++ ){
rowCache.push(i);
}
rowCache.push(rows[1]);
renderContainers.body.prevScrollTop = 100;
renderContainers.body.visibleRowCache = rowCache;
renderContainers.body.visibleColumnCache = [column];
grid.renderContainers = renderContainers;

// try to scroll to row 10
grid.scrollToIfNecessary(rowCache[9], column).then(function(scrollEvent){
expect(scrollEvent).toBeUndefined();
});

$scope.$apply();
});

it('should not scroll.y when scrollpercentage > 100% when row is more then top boundry', function() {
// row is more then the top boundary
var rowCache = [];
for ( var i = 0; i < 9; i++ ){
rowCache.push(i);
}
rowCache.push(rows[1]);
renderContainers.body.prevScrollTop = 300;
renderContainers.body.visibleRowCache = rowCache;
renderContainers.body.visibleColumnCache = [column];
grid.renderContainers = renderContainers;

// try to scroll to row 10
grid.scrollToIfNecessary(rowCache[9], column).then(function(scrollEvent){
expect(scrollEvent).toBeUndefined();
});

$scope.$apply();
});
});

describe('constructor', function() {
it('should throw an exception if no id is provided', function() {
expect(function() {
Expand Down