Tabs does not respect setting selectedIndex
See original GitHub issueWe have an md-tab-group with a number of md-tabs and we’re setting an initial selected tab using the selectedIndex
property and the user can then select to reset back to that initial tab. The problem we’re finding is that if the user navigates using the labels to other tabs then chooses to reset back to the initial tab it doesn’t work.
We’ve traced through and we can see that selectedIndex
is never updated by the tab component when the user selects other tabs, so when we try to set selectedIndex
back to the initial value, the angular change detection kicks in and says nothing changed.
We know this is early days but is this behaviour expected to change? Can we submit a PR to fix it? Or is there a rationale for it being this way?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
`selectedIndex` only sets the selected tab for the first time
The issue occurs because the same variable is mutated simultaneously by the Tabs component and the code in the onClick event handler. The ......
Read more >TabControl.SelectedIndex Property (System.Windows.Forms)
Gets or sets the index of the currently selected tab page. ... The default is -1, which is also the value if no...
Read more >How can I change a tab without causing selectedIndexChange
What I want is that the tab will change on every button click but the event handler that is attached to the selectedIndexChange...
Read more >Tabstrip selected index issue in Kendo UI for jQuery - Telerik
Hi Telerik Team, Here I have got three tabs. I want to get tabindex while selecting each tab and based on this tabindex...
Read more >Radzen Tab does not output correct selected index
This causes problems because it forces the developer to ensure that none of the tabs are set to selected after every time they...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@iainmckay I’m working on a fix for this, but wanted to explain why the bug exists. When you initially include tabs, you use a one-way binding in order to pass your
selectedIndex
into the tabs component:<md-tab-group [selectedIndex]="selectedIndex">
.When you click around inside of tabs, this changes the internal value for
selectedIndex
, but since this is only a one-way binding, your component’s value is never updated.When you attempt to change tabs by setting your component value for
selectedIndex
, you are setting it to the same value that it already has, which is why change detection does not detect any changes.In order to fix this, currently, you would have to keep a reference to the
tab-group
in your component and set its value explicitly:Another option (which is what I am working on adding) is to use a two-way binding so that your local
selectedIndex
will be updated when the internal value changes. This would look like this:Hopefully that makes sense.
why cant you put this in documentation? Getting activeTabIndex is most basic requirements for tabs.
Somehow i find that documentation of google is always incomplete.