[Tabs] Ability to hide tabs header
Bug, feature request, or proposal:
Feature request
What is the expected behavior?
The mat-tab-group should expose a property using which the header can be hidden. Setting the property to true should hide the header of the mat-tab-group.
What is the current behavior?
At the moment. in order to hide the header, I have to override the default styles of the class ".mat-tab-header" and set the display property to none along with setting component's encapsulation to encapsulation: ViewEncapsulation.None. Given below is an example how I am currently hiding the tab header:
CSS Styles
.header-less-tabs.mat-tab-group .mat-tab-header {
display: none;
}
TypeScript
import { Component, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
}
Html Template
<mat-tab-group class="header-less-tabs">
<mat-tab label="Tab 1">Content 1</mat-tab>
<mat-tab label="Tab 2">Content 2</mat-tab>
</mat-tab-group>
What are the steps to reproduce?
Here is a link to StackBlitz Demo of what I am looking to achieve.
What is the use-case or motivation for changing an existing behavior?
I have an app where I am loading different contents/sections inside the mat-tab-group, and I am using a sidebar with the buttons to navigate. Also, the navigation happens from inside any tab. I do not have any routes in the app, so using "mat-tab-nav-bar" is not an option.
I would very much like this feature too.
I have a list of products categories and only some have sub categories. I am displaying the products in a sub category in a tab control, but when there is only a single sub category I don't want to display the tab control header. Would be much simpler template if I had this property.
Is this feature going to be added anytime soon?
Is this feature going to be added sometime? or has anyone figured out a workaround to hide it?
@andystroz faisalmuhammad's example on StackBlitz is pretty straightforward. I used it like this:
In styles.css:
.header-less-tabs .mat-tab-group .mat-tab-header { display: none; }
In the template:
<div [ngClass]="{ 'header-less-tabs': formTabs.length === 1}">
--- <mat-tab-group ...>
--- </mat-tab-group>
</div>
where formTabs is an array variable in my component.
Really wish some of these 'low priority' tasks that should be simple to implement could be prioritized more highly :-/
Please implement this feature. It will allow using mat-tab-group as missing carousel control (from bootstrap).
length
Even simpler without the need of the extra wrapper or the component variable:
In styles.css:
.header-less-tabs .mat-tab-header { display: none; }
In the template:
<mat-tab-group #matTabGroup [class.header-less-tabs]="matTabGroup._tabs.length <= 1">
Lending my voice to the crowd, lest this issue fall victim to the auto-close.
Tabs are awesome, and like others here, I am looking to separate the tab header from the tab group or hide it completely, so I can use tabs for navigation where routing is not possible.
Yeah, this feature would be really cool!!
I'd like to not only hide the tab group, I'd like to hide a specific matTabLabel.
By hiding a label, you could still navigate to the content via button somewhere else and you'd get all of the nice slide in/slide out effects for free.
Should that be a separate feature request?
Agree. I'd like a multi-step process without the tab labels but with all the cool animations built-in. I've got a sign-in page with three phases: (1) enter your email (2) wait for email to be sent, like a big progress ring, (3) done, go check your email.
Thanks for bringing this up! I found this after hours of searching...
here's how I did it: add this to the css file and presto!
::ng-deep .mat-tab-group > .mat-tab-header{
display: none;
}
I would like this feature.
The tabs component follows the guidance of the tabs accessibility pattern: https://www.w3.org/WAI/ARIA/apg/patterns/tabpanel/
The header plays an important part in this pattern to help all users navigate the content. Displaying the tabpanel elements without a tablist containing a set of tab elements would break this interaction.
Some comments alude to having the tablist elsewhere on the page (e.g. a side nav) which could be a valid workaround. However this sounds closer to the mat-tab-nav-bar usage which does allow separation of links and content. Note that the router is not required to use the nav bar.
Other comments seem to want the content sliding interaction simply for the animation. In those cases I recommend building a custom component that animates content. The tab group should not be favored simply for its visual interaction, since it implies an accessibility pattern that means something for users depending on tools like screen readers.
I had to create my own whole tab control because of this. Not because I wanted to hide the bar, not because I wanted the animation but because most of the time my tab control only contains one item. In which case tabs made no sense and wasted space. When developers have to do this I guarantee accessibility ends up far worse off!
Perhaps reconsider for this reason alone? HideNavigationIfOnlyOneTab
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.