Angular Material 2 Tabs with fixed (sticky) tab labels

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Angular Material 2 Tabs with fixed (sticky) tab labels



I have a layout using Angular Material 2 mat-sidenav layout with a mat-tab layout in the mat-sidenav-content section. I am trying to make the mat-tab-labels sticky so they are always visible, and still allow the dynamic tab-content to scroll. I can get the labels to stay fixed by setting overflow: hidden on the mat-sidenav-content and then set overflow: scroll on the mat-tab-body-wrapper element, but I have to set a fixed height to get the tab-content to scroll, but I have dynamic content so a fixed height isn't an option. Is there a way I can get my sticky labels and scrolling too without setting a fixed height?


mat-sidenav


mat-sidenav-content


mat-tab-labels


overflow: hidden


mat-sidenav-content


overflow: scroll


mat-tab-body-wrapper


tab-content



Below is a demo. Shrink the vertical height of your window until it covers part of the "Large content" div. It will not scroll. Then uncomment the mat-tab-group css that sets a height and it will scroll as desired (but a fixed height).


mat-tab-group



https://stackblitz.com/edit/angular-rty6oe?file=app%2Fsidenav-fixed-example.css



UPDATE



Ok, @Dakota Maker's answer solved the immediate problem, and also reminded me of what I was originally trying to fix that brought me to the point of not being able to scroll. I updated my example app to reflect my real app better. I have a sub-header inside the sidenav-content area that sits above the mat-tab-group, and when scrolling it never gets to the bottom unless the window height is large enough because the header seems to have pushed the content down and off the screen. I can add a margin to the bottom of the content to compensate for the sub-header, but the sub-header area height can change.



If I should accept the answer to the original question and open a new question, please advise.




1 Answer
1



Set height:100% one the mat-tab-groups and you will be able to scroll and there won't be a big white block in the middle of the large content


height:100%


mat-tab-groups



EDIT TO ACCOMPANY OP's UPDATE:



You can add something like bottom:12px to the .mat-tab-body-wrapper to give it a fixed amount of space at the bottom. This will end up giving you some of the overflow at the top of the wrapper some overlap with where the tabs are at, but you should be able to work that out also adding in something like margin-top:12px to the same block. Hope this helps out!


bottom:12px


.mat-tab-body-wrapper


margin-top:12px





That solved the immediate problem, but please view my edit.
– andyrue
Aug 8 at 19:34





Thanks for your help. Since the height is dynamic, I ended up creating a variable that would get updated with the current height of the sub-header when it changes and binding it to margin-bottom of the .mat-tab-body-wrapper.
– andyrue
Aug 9 at 12:17


margin-bottom


.mat-tab-body-wrapper






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard