Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the Angular material tab's mat-ink-bar to take the width of tab header text width

I want the Angular material tab's mat-ink-bar to take the width of the tab header text's width. Currently it is larger than the tab header text width.

Following image shows how it looks now.

Current look

Following image shows how I want it to be.

How I want the mat-tab-ink-bar to look

Could you help me on how to make this happen?

like image 357
nuwan.chamara Avatar asked May 01 '18 07:05

nuwan.chamara


People also ask

How do I select a mat tab by default?

Set a variable called tabIndex for the selectedIndex in the mat-tab-group . Declare the tabIndex variable in app. component. ts and define a method called setTab to change the selected tab.

How do I change the height of my mat tab?

By default, the tab group will not change its height to the height of the currently active tab. To change this, set the dynamicHeight input to true. The tab body will animate its height according to the height of the active tab.

How do you conditionally prevent users from navigating to other tab in Mat-tab-group?

The solution 🕶 First, we need to add a click listener on the mat-tab-group and disable all tabs because if tabs are not disabled then the user will be able to navigate on them and we want to navigate on tabs conditionally not manually.

What is Mat tab in angular?

Tabs and navigation While <mat-tab-group> is used to switch between views within a single route, <nav mat-tab-nav-bar> provides a tab-like UI for navigating between routes.


1 Answers

enter image description here I achieved this by removing min-width and padding on the .mat-tab-label class.. and adding margin as per my requirement to keep the labels apart. this worked as mat-ink-bar takes the width of mat-tab-label which was set min-width to 160px;

SCSS:

mat-tab-header {
border-bottom: none !important;
.mat-tab-label-container {
    margin-bottom: 12px;
    .mat-tab-labels {
    .mat-tab-label {
        padding: 0 0 !important;
        min-width: 10px;
        margin-left: 95px;
    }
    }
}
}
like image 102
divya bharathi Narla Avatar answered Oct 27 '22 00:10

divya bharathi Narla