I am trying to lay out tabs on my website and I am using md-tab-group to achieve this. I am unable to get the ink-bar to be on the default but however, the content written on the respective tab is available. The ink-bar appears on click and not on init of the page. Below is my code
<md-tab-group dynamicHeight = "true" >
<md-tab id="hello1" label="Tab 1">
<!-- some content here -->
</md-tab>
<md-tab id="hello2" label="Tab 2">
<!-- some content here -->
</md-tab>
</md-tab-group>
The solutions that I have tried are a) selectedIndex not working in md-tab-group when dynamically generating tabs b) Angular Material Tabs SelectedIndex 0 not working
Any idea what am I overlooking?
I was getting this same issue with
mat-tab-nav-bar
, which is the same control but where you don't define blocks of content for each tab in advance.Turns out (for me) that my tab bar was not visible on the page when it was first being initialized. It was actually nested within another tab, but the point it that it can't figure out the width when it's not visible.
So everything worked perfectly except the
inkBar
(the blue bar) had a width of0px
.The solution is going to vary depending upon your page, but this may help diagnose things.
this._inkBarPositioner
in your browserIf you're using nested tabs and seeing this issue you may be able to fix it by switching to a templated tab (which is called asynchronously loaded tab in the docs).
The function
MatTabBar._alignInkBarToSelectedTab
is private but you could try to call it as a last resort once you know the control is actually visible.Hacky solution #1
This css is targeted for
mat-tab-nav-bar
(the standalone tab navigation bar) and notmat-tab-group
/mat-tab
but could almost certainly be adjusted to fit the tab / group control.