Skip to content

Commit 4c25e86

Browse files
committed
address comments
1 parent 7da621d commit 4c25e86

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

src/cdk/scrolling/virtual-scroll-viewport.spec.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import {ArrayDataSource} from '@angular/cdk/collections';
22
import {CdkVirtualForOf, CdkVirtualScrollViewport, ScrollingModule} from '@angular/cdk/scrolling';
33
import {dispatchFakeEvent} from '@angular/cdk/testing';
4-
import {Component, Input, ViewChild, ViewContainerRef, ViewEncapsulation} from '@angular/core';
4+
import {
5+
Component,
6+
Input,
7+
TrackByFunction,
8+
ViewChild,
9+
ViewContainerRef,
10+
ViewEncapsulation
11+
} from '@angular/core';
512
import {ComponentFixture, fakeAsync, flush, TestBed} from '@angular/core/testing';
613
import {animationFrameScheduler, Subject} from 'rxjs';
714

@@ -727,7 +734,7 @@ class FixedSizeVirtualScroll {
727734
@Input() minBufferPx = 0;
728735
@Input() maxBufferPx = 0;
729736
@Input() items = Array(10).fill(0).map((_, i) => i);
730-
@Input() trackBy;
737+
@Input() trackBy: TrackByFunction<number>;
731738
@Input() templateCacheSize = 20;
732739

733740
scrolledToIndex = 0;
@@ -777,7 +784,7 @@ class FixedSizeVirtualScrollWithRtlDirection {
777784
@Input() itemSize = 50;
778785
@Input() bufferSize = 0;
779786
@Input() items = Array(10).fill(0).map((_, i) => i);
780-
@Input() trackBy;
787+
@Input() trackBy: TrackByFunction<number>;
781788
@Input() templateCacheSize = 20;
782789

783790
scrolledToIndex = 0;

src/cdk/scrolling/virtual-scroll-viewport.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
285285
// For a horizontal viewport in a right-to-left language we need to calculate what `scrollRight`
286286
// would be.
287287
offset = this.orientation == 'horizontal' && this._dir && this._dir.value == 'rtl' ?
288-
Math.max(0, this._totalContentSize - this._viewportSize - offset) : offset;
288+
this._getRightOffsetAsLeftOffset(offset) : offset;
289289

290290
if (supportsScrollBehavior()) {
291291
const offsetDirection = this.orientation === 'horizontal' ? 'left' : 'top';
@@ -315,7 +315,7 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
315315
// For a horizontal viewport in a right-to-left language we need to calculate what
316316
// `scrollRight` would be.
317317
return this._dir && this._dir.value == 'rtl' ?
318-
Math.max(0, this._totalContentSize - this._viewportSize - offset) : offset;
318+
this._getRightOffsetAsLeftOffset(offset) : offset;
319319
}
320320
return this.elementRef.nativeElement.scrollTop;
321321
}
@@ -387,4 +387,9 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
387387
fn();
388388
}
389389
}
390+
391+
/** Expresses an offset from the right as the equivalent offset from the left. */
392+
private _getRightOffsetAsLeftOffset(offset: number): number {
393+
return Math.max(0, this._totalContentSize - this._viewportSize - offset);
394+
}
390395
}

src/demo-app/demo-app/demo-app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ <h1>Angular Material Demos</h1>
4141
</div>
4242
</mat-toolbar>
4343

44-
<div #root="dir" dir="rtl" class="demo-content">
44+
<div #root="dir" dir="ltr" class="demo-content">
4545
<router-outlet></router-outlet>
4646
</div>
4747
</div>

0 commit comments

Comments
 (0)