mat-table with sticky header doesn't work in mat-tab-group
Reproduction
Stackblitz Link: https://stackblitz.com/edit/components-issue-any3dl
Steps to reproduce:
- Put a
mat-tableinside amat-tab-groupand setsticky: true - scroll down
Expected Behavior
Table header should be sticky
Actual Behavior
Table header is not sticky
Environment
- Angular: 8.0.0
- CDK/Material: 8.0.1
- Browser(s): Chrome 75
- Operating System (e.g. Windows, macOS, Ubuntu): macOS Mojave 10.14.5
That's because the scroll now happens on the tab itself rather than the table. You need to make sure the tab has a height: 100% (or some defined height) so that the table can take over the scroll.
I don't think there's anything Angular Components can do, as it's a case by case decision whether the tab or its content should act as the scroll container.
Can you provide an example? I tried setting height: 100% at several places, but the header still isn't sticky.
Bonus question: When is it useful to have either tab or content as scroll container?
I'm on mobile so I can't dig into the example, sorry. It may well be that the structure of Material tabs currently don't allow setting it at the correct place, in that case that is something that should be enabled.
Bonus question: When is it useful to have either tab or content as scroll container?
I wasn't precise enough above. The tab never scrolls right now, it just doesn't have a defined height so it expands to fit its content. With the sticky header table the problem is that the table needs some defined height, otherwise the header never has a reason to stick.
The only two cases where it makes sense to use this 100% height thing that I can think of are some sticky content in the tab (header or footer) or when wanting to vertically center something in the tab (as vertically centering in a parent that is fit to content doesn't make sense).
Note that 100% height isn't always the correct answer. The tab itself of course has a parent as well and it somewhat depends on the layout you're talking about. For example if above the tab you have some text, then 100% height on the tab would cause page scroll (and then table scroll inside the tab, so two scroll bars) when likely you'd want to have the text and tab combined to be 100% viewport height.
I have 2 nearly identical views within a <router-outlet>.
The first one is: <mat-toolbar></mat-toolbar><mat-table></mat-table>
And the second one is: <mat-toolbar></mat-toolbar><mat-tab-group><mat-table></mat-table></mat-tab-group>
The first one works with sticky header, and the second one doesn't. The only difference is the tabs component. Though there isn't much "parent" available. When I put the table below the the tabs component, it works perfectly.
Maybe you got some time in the next days to help me. I'm clueless...
Setting the height of mat-tab-group to 100vh seems to solve your problem.
<mat-tab-group style="height: 100vh">
@jymdman Not really. This only works, if there's nothing above the tabs.
I've edited the Stackblitz example. It now has a toolbar above the tabs, and a card below.
If you remove the Tabs and just keep toolbar, table, card you can see what behavior I want (just with the additional tabs)
I know found the "issue". There are lot's of overflow: hidden on mat-tab-body-*
Here's what I need to do:
mat-tab-body-wrappermat-tab-body-activemat-tab-body-contentOn all CSS classes setoverflow: initialoroverflow: visible
But view encapsulation is getting in the way. It only works when defining those styles globally in styles.scss. I now use a trigger CSS class to apply my custom styles:
.tab-custom-overflow .mat-tab-body-wrapper {
overflow: visible !important;
}
.tab-custom-overflow .mat-tab-body-active {
overflow: visible !important;
}
.tab-custom-overflow .mat-tab-body-content {
overflow: visible !important;
}
And then use it in the template:
<mat-tab-group class="tab-custom-overflow">
...
</mat-tab-group>
But now I can't get horizontal scrolling for the table working...
Also, the animation while changing tabs isn't very pleasing. Do you have any progress on this issue?
The @benneq answer worked for me, thanks man !
I declared the rules directly in my component, to avoid adding a class in styles.scss. Therefore I had to add the ::ng-deep prefix to the selector in order to make it work.
This seems to be an issue with layout and styles that can be resolved with overrides. I dont believe there is any action we can take here
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.