Skip to content

Commit e0782e6

Browse files
crisbetoannieyw
authored andcommitted
fix(tabs): mark tab body as a scrollable container (#16344)
Since the tab body content can be scrollable and consumers don't have access to the DOM element, we have to mark it as a CdkScrollable in order to allow for overlays inside the tabs to reposition. Fixes #8405. (cherry picked from commit 24d20fb)
1 parent b62e248 commit e0782e6

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/material/tabs/tab-body.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
params: {animationDuration: animationDuration}
55
}"
66
(@translateTab.start)="_onTranslateTabStarted($event)"
7-
(@translateTab.done)="_translateTabComplete.next($event)">
7+
(@translateTab.done)="_translateTabComplete.next($event)"
8+
cdkScrollable>
89
<ng-template matTabBodyHost></ng-template>
910
</div>

src/material/tabs/tab-body.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {AfterContentInit, Component, TemplateRef, ViewChild, ViewContainerRef} f
55
import {waitForAsync, ComponentFixture, TestBed} from '@angular/core/testing';
66
import {MatRippleModule} from '@angular/material/core';
77
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
8+
import {By} from '@angular/platform-browser';
9+
import {ScrollingModule, CdkScrollable} from '@angular/cdk/scrolling';
810
import {MatTabBody, MatTabBodyPortal} from './tab-body';
911
import {Subject} from 'rxjs';
1012

@@ -178,6 +180,33 @@ describe('MatTabBody', () => {
178180

179181
expect(fixture.componentInstance.tabBody._position).toBe('left');
180182
});
183+
184+
it('should mark the tab body content as a scrollable container', () => {
185+
TestBed
186+
.resetTestingModule()
187+
.configureTestingModule({
188+
imports: [
189+
CommonModule,
190+
PortalModule,
191+
MatRippleModule,
192+
NoopAnimationsModule,
193+
ScrollingModule
194+
],
195+
declarations: [
196+
MatTabBody,
197+
MatTabBodyPortal,
198+
SimpleTabBodyApp,
199+
]
200+
})
201+
.compileComponents();
202+
203+
const fixture = TestBed.createComponent(SimpleTabBodyApp);
204+
const tabBodyContent = fixture.nativeElement.querySelector('.mat-tab-body-content');
205+
const scrollable = fixture.debugElement.query(By.directive(CdkScrollable));
206+
207+
expect(scrollable).toBeTruthy();
208+
expect(scrollable.nativeElement).toBe(tabBodyContent);
209+
});
181210
});
182211

183212

0 commit comments

Comments
 (0)