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.
Following image shows how I want it to be.
Could you help me on how to make this happen?
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.
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.
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.
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.
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;
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With