Skip to content

Commit dbe27c4

Browse files
crisbetojelbourn
authored andcommittedDec 3, 2018
fix(scrolling): default to vertical CSS class for invalid orientation (#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.
1 parent 3f1588f commit dbe27c4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

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

+22
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,28 @@ describe('CdkVirtualScrollViewport', () => {
133133
expect(viewport.elementRef.nativeElement.scrollWidth).toBe(10000);
134134
}));
135135

136+
it('should set a class based on the orientation', fakeAsync(() => {
137+
finishInit(fixture);
138+
const viewportElement: HTMLElement =
139+
fixture.nativeElement.querySelector('.cdk-virtual-scroll-viewport');
140+
141+
expect(viewportElement.classList).toContain('cdk-virtual-scroll-orientation-vertical');
142+
143+
testComponent.orientation = 'horizontal';
144+
fixture.detectChanges();
145+
146+
expect(viewportElement.classList).toContain('cdk-virtual-scroll-orientation-horizontal');
147+
}));
148+
149+
it('should set the vertical class if an invalid orientation is set', fakeAsync(() => {
150+
testComponent.orientation = 'diagonal';
151+
finishInit(fixture);
152+
const viewportElement: HTMLElement =
153+
fixture.nativeElement.querySelector('.cdk-virtual-scroll-viewport');
154+
155+
expect(viewportElement.classList).toContain('cdk-virtual-scroll-orientation-vertical');
156+
}));
157+
136158
it('should set rendered range', fakeAsync(() => {
137159
finishInit(fixture);
138160
viewport.setRenderedRange({start: 2, end: 3});

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function rangesEqual(r1: ListRange, r2: ListRange): boolean {
4646
host: {
4747
'class': 'cdk-virtual-scroll-viewport',
4848
'[class.cdk-virtual-scroll-orientation-horizontal]': 'orientation === "horizontal"',
49-
'[class.cdk-virtual-scroll-orientation-vertical]': 'orientation === "vertical"',
49+
'[class.cdk-virtual-scroll-orientation-vertical]': 'orientation !== "horizontal"',
5050
},
5151
encapsulation: ViewEncapsulation.None,
5252
changeDetection: ChangeDetectionStrategy.OnPush,

0 commit comments

Comments
 (0)
Please sign in to comment.