Skip to content

Commit

Permalink
fix: Virtual scroll scrollTop value calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
anjmao committed Sep 30, 2017
1 parent e95a60c commit 1b0ed3c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/src/ng-select.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</span>
</div>

<div class="as-menu-outer" [ngStyle]="{'visibility': isOpen ? 'visible' : 'hidden'}">
<div class="as-menu-outer">
<virtual-scroll role="listbox" class="as-menu" [bufferAmount]="4" [items]="itemsList.filteredItems" (update)="viewPortItems = $event">
<div class="as-option" role="option" (click)="toggle(item)" (mouseover)="onItemHover(item)"
*ngFor="let item of viewPortItems;"
Expand Down
7 changes: 4 additions & 3 deletions src/lib/src/virtual-scroll.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,12 @@ export class VirtualScrollComponent implements OnInit, OnChanges, OnDestroy {
return;
}

let d = this.calculateDimensions();
const d = this.calculateDimensions();
const buffer = Math.floor(d.viewHeight / d.childHeight) - 1;
el.scrollTop = (Math.floor(index / d.itemsPerRow) * d.childHeight)
- (d.childHeight * Math.min(index, this.bufferAmount));
- (d.childHeight * Math.min(index, buffer));
this.refresh();
}
};

private refreshHandler = () => {
this.refresh();
Expand Down

0 comments on commit 1b0ed3c

Please sign in to comment.