Skip to content

fix(scrolling): default to vertical CSS class for invalid orientation #14145

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

Merged
merged 1 commit into from
Nov 27, 2018
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
22 changes: 22 additions & 0 deletions src/cdk/scrolling/virtual-scroll-viewport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,28 @@ describe('CdkVirtualScrollViewport', () => {
expect(viewport.elementRef.nativeElement.scrollWidth).toBe(10000);
}));

it('should set a class based on the orientation', fakeAsync(() => {
finishInit(fixture);
const viewportElement: HTMLElement =
fixture.nativeElement.querySelector('.cdk-virtual-scroll-viewport');

expect(viewportElement.classList).toContain('cdk-virtual-scroll-orientation-vertical');

testComponent.orientation = 'horizontal';
fixture.detectChanges();

expect(viewportElement.classList).toContain('cdk-virtual-scroll-orientation-horizontal');
}));

it('should set the vertical class if an invalid orientation is set', fakeAsync(() => {
testComponent.orientation = 'diagonal';
finishInit(fixture);
const viewportElement: HTMLElement =
fixture.nativeElement.querySelector('.cdk-virtual-scroll-viewport');

expect(viewportElement.classList).toContain('cdk-virtual-scroll-orientation-vertical');
}));

it('should set rendered range', fakeAsync(() => {
finishInit(fixture);
viewport.setRenderedRange({start: 2, end: 3});
Expand Down
2 changes: 1 addition & 1 deletion src/cdk/scrolling/virtual-scroll-viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function rangesEqual(r1: ListRange, r2: ListRange): boolean {
host: {
'class': 'cdk-virtual-scroll-viewport',
'[class.cdk-virtual-scroll-orientation-horizontal]': 'orientation === "horizontal"',
'[class.cdk-virtual-scroll-orientation-vertical]': 'orientation === "vertical"',
'[class.cdk-virtual-scroll-orientation-vertical]': 'orientation !== "horizontal"',
},
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
Expand Down