Reputation: 609
I'm trying to position my image sticky with
position: -webkit-sticky;
position: sticky;
top: 1px;
however cannot achieve it.
HTML:
<mat-tab-group class="user-tabs"
(selectedTabChange)="changeUserTab($event)">
<mat-tab label="Selectable Tasks">
<mat-tab-group class="user-chats"
(selectedTabChange)="changeChatTab($event)">
<mat-tab *ngFor="let chat of userData.chats; let i = index;">
<img>
</mat-tab>
</mat-tab-group>
</mat-tab>
</mat-tab-group>
I have tabs inside tabs, yes. Does anybody has some solution for this? Thanks.
Upvotes: 6
Views: 1979
Reputation: 1
Angular 15+ (After mdc migration)
HTML:
<mat-tab-group
id="my-tab-group"
mat-stretch-tabs
[selectedIndex]="tab"
(selectedIndexChange)="changeTab($event)"
>
<mat-tab>
<custom-component-with-sticky-content></custom-component-with-sticky-content>
</mat-tab>
<mat-tab>
<my-second-component></my-second-component>
</mat-tab>
CSS:
::ng-deep #my-tab-group .mat-mdc-tab-body-wrapper .mat-mdc-tab-body.mat-mdc-tab-body-active {
overflow: visible !important;
}
::ng-deep #my-tab-group .mat-mdc-tab-body-wrapper {
overflow: visible !important;
}
::ng-deep #my-tab-group .mat-mdc-tab-body-wrapper .mat-mdc-tab-body-content {
overflow: visible !important;
}
Upvotes: 0
Reputation: 444
I was able to get this to work using *ngTemplateOutlet (and some help from other answers, but weren't enough without ngTemplateOutlet)
HTML:
<div class="main-container" id="main-container">
<mat-tab-group id="tabs" #tabs>
<mat-tab label="myTabLabel">
(your code here)
</mat-tab>
</mat-tab-group>
</div>
<ng-container *ngTemplateOutlet="idek"> </ng-container>
<ng-template #idek>
<mat-toolbar color="warn" >Second Toolbar</mat-toolbar>
<div id="add-spacing">
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
</div>
</ng-template>
CSS:
::ng-deep #tabs .mat-tab-body-wrapper .mat-tab-body.mat-tab-body-active {
overflow: visible !important;
}
::ng-deep #tabs .mat-tab-body-wrapper {
overflow: visible !important;
}
::ng-deep #tabs .mat-tab-body-wrapper .mat-tab-body-content {
overflow: visible !important;
}
mat-toolbar {
--default-height: 50px !important;
}
mat-toolbar {
position: sticky !important;
top: var(--default-height) !important;
}
.main-container {
(your code here)
}
The result:
Upvotes: 1
Reputation: 740
Here is a solution:
<mat-tab-group
id="my-tab-group"
mat-stretch-tabs
[selectedIndex]="tab"
(selectedIndexChange)="changeTab($event)"
>
<mat-tab>
<custom-component-with-sticky-content></custom-component-with-sticky-content>
</mat-tab>
<mat-tab>
<my-second-component></my-second-component>
</mat-tab>
</mat-tab-group>
...
and the css:
styles: [
`
/* Needed in order to allow the sticky content */
::ng-deep #my-tab-group .mat-tab-body-wrapper .mat-tab-body.mat-tab-body-active {
overflow: visible !important;
}
::ng-deep #my-tab-group .mat-tab-body-wrapper {
overflow: visible !important;
}
::ng-deep #my-tab-group .mat-tab-body-wrapper .mat-tab-body-content {
overflow: visible !important;
}
`,
],
Upvotes: 5
Reputation: 609
Found a reason - it won't work when at least one of the parent has overflow
set to hidden
and that's the case with mat-tabs.
Upvotes: 0