-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(tabs): maintain selected tab when new tabs are added or removed #9132
fix(tabs): maintain selected tab when new tabs are added or removed #9132
Conversation
fd1827a
to
3fb1921
Compare
Is there any concern about a race when changing |
Maintains the `selectedIndex` of the current tab when a new tab is added or removed. Previously, changing the amount of tabs would shift the array, causing a different tab to be selected. Fixes angular#7738.
3fb1921
to
3e54a92
Compare
Sorry @andrewseguin, I just got around to rebasing this PR and saw your comment from a while ago. I think that there shouldn't be an issue with race conditions since the tab changes event will be fired after the |
This fix seems to have broken existing expected functionality. On this page: https://material.angular.io/components/tabs/examples Let me know if you want me to open a new bug for this. |
…removed Due to a recent change that ensures that the selected tab will be kept selected if a new tab has been added or removed (angular#9132), updating the `selectedIndex` at the same time will not have any effect because it will be overwritten by the `_tabs.change` (from angular#9132). In order to guarantee that developers can add new tabs and immediately select them once the change detection runs, we only re-index the `selectedIndex` (purpose of angular#9132) whenever the `indexToSelect` has not explicitly changed (through developer bindings for example) Fixes angular#12038
…removed Due to a recent change that ensures that the selected tab will be kept selected if a new tab has been added or removed (angular#9132), updating the `selectedIndex` at the same time will not have any effect because it will be overwritten by the `_tabs.change` (from angular#9132). In order to guarantee that developers can add new tabs and immediately select them once the change detection runs, we only re-index the `selectedIndex` (purpose of angular#9132) whenever the `indexToSelect` has not explicitly changed (through developer bindings for example) Fixes angular#12038
…removed Due to a recent change that ensures that the selected tab will be kept selected if a new tab has been added or removed (#9132), updating the `selectedIndex` at the same time will not have any effect because it will be overwritten by the `_tabs.change` (from #9132). In order to guarantee that developers can add new tabs and immediately select them once the change detection runs, we only re-index the `selectedIndex` (purpose of #9132) whenever the `indexToSelect` has not explicitly changed (through developer bindings for example) Fixes #12038
…removed Due to a recent change that ensures that the selected tab will be kept selected if a new tab has been added or removed (angular#9132), updating the `selectedIndex` at the same time will not have any effect because it will be overwritten by the `_tabs.change` (from angular#9132). In order to guarantee that developers can add new tabs and immediately select them once the change detection runs, we only re-index the `selectedIndex` (purpose of angular#9132) whenever the `indexToSelect` has not explicitly changed (through developer bindings for example) Fixes angular#12038
…removed Due to a recent change that ensures that the selected tab will be kept selected if a new tab has been added or removed (#9132), updating the `selectedIndex` at the same time will not have any effect because it will be overwritten by the `_tabs.change` (from #9132). In order to guarantee that developers can add new tabs and immediately select them once the change detection runs, we only re-index the `selectedIndex` (purpose of #9132) whenever the `indexToSelect` has not explicitly changed (through developer bindings for example) Fixes #12038
This still doesn't seem to be working ( https://stackblitz.com/angular/rkdrmvvyyjn?file=app%2Ftab-group-dynamic-example.ts v6.4.1). The focus after open doesn't seem to function correctly. I fix this wrapping the index setter method in a setTimeout. addTab(selectAfterAdding: boolean) {
this.tabs.push('New');
if (selectAfterAdding) {
setTimeout( () => {
this.selected.setValue(this.tabs.length - 1);
})
}
} |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Maintains the
selectedIndex
of the current tab when a new tab is added or removed. Previously, changing the amount of tabs would shift the array, causing a different tab to be selected.Fixes #7738.