Skip to content

Commit

Permalink
fix(scrolling): default to vertical CSS class for invalid orientation (
Browse files Browse the repository at this point in the history
…#14145)

Since there are some structural styles that depend on the `cdk-virtual-scroll-orientation-*` classes, it's important that at least one of them is on the element at any time. Currently the user can end up with none if they did something like `orientation="horizontal-with-a-typo"`. These changes default to vertical, unless the value is `horizontal` which mirrors all the internal logic.
  • Loading branch information
crisbeto authored and jelbourn committed Dec 3, 2018
1 parent 3f1588f commit dbe27c4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/cdk/scrolling/virtual-scroll-viewport.spec.ts
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
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

0 comments on commit dbe27c4

Please sign in to comment.