Skip to content
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

[Tabs] Two-way binding for tabs only work on initializing component #1692

Closed
aecz opened this issue Nov 2, 2016 · 17 comments · Fixed by #2014
Closed

[Tabs] Two-way binding for tabs only work on initializing component #1692

aecz opened this issue Nov 2, 2016 · 17 comments · Fixed by #2014
Assignees
Labels
P2 The issue is important to a large percentage of users, with a workaround

Comments

@aecz
Copy link

aecz commented Nov 2, 2016

What is the expected behavior?

When changing the variable bind to selectedIndex, the active tab should change.

What is the current behavior?

The active tab stays the same.

What are the steps to reproduce?

http://plnkr.co/edit/cX9OKA?p=preview

Which versions of Angular, Material, OS, browsers are affected?

@angular : 2.0.0
@angular/material : 2.0.0-alpha.9-3
Windows 7

@jelbourn jelbourn added the P2 The issue is important to a large percentage of users, with a workaround label Nov 2, 2016
@csabattilas
Copy link

is this in progress? if not I can take it. thanks

@csabattilas
Copy link

The issue with the plunkr example is that the tab is added after the setter for the selectedIndex kicks in so the setter becomes invalid. Any hint how to work around this? One idea I got is to save save the selectedIndex value and when the tab is added set it again. what do you think? thanks.

@csabattilas
Copy link

@jelbourn @andrewseguin you want me to take this one? thanks

@jelbourn
Copy link
Member

@krigton: @andrewseguin is going to tackle this one

@csabattilas
Copy link

@jelbourn oki. i tackled a bit myself that's why i asked. any other issue you want me to address? thanks

@andrewseguin
Copy link
Contributor

I've been looking into this and the issue can be resolved easily but we are running into a problem of syncing the animiations correctly. Will spend some more time on this today to see if we can come up with an ideal solution.

@andrewseguin andrewseguin changed the title Two-way binding for tabs only work on initializing component [Tabs] Two-way binding for tabs only work on initializing component Nov 16, 2016
@csabattilas
Copy link

What you mean by synching the animations correctly?

@andrewseguin
Copy link
Contributor

andrewseguin commented Nov 29, 2016

When a selection is made, it may be on a new tab. Often we'll see someone add a tab to their list of tabs and immediately want to select it. In this case, we want to have it animate it in from the left or right. Went through many iterations until I figured out how to do this. The difficult part is that the selectedIndex setter is handled by angular before the view's tabs are updated.

@PTC-JoshuaMatthews
Copy link

Still having this issue on beta2, beta3 won't build in webpack for me. Is there any workaround for this? Currently can't find any way to set selected tab programmatically which is frankly unacceptable for a tab control!

@AlanCrevon
Copy link

AlanCrevon commented May 2, 2017

Same thing here :/

Edit : using master (02/05/2017)

EDIT 2 : PTC-JoshuaMatthews : it works using plain old [(selectedIndex)] :)

@PTC-JoshuaMatthews
Copy link

PTC-JoshuaMatthews commented May 2, 2017

@AlanCrevon

I am on "@angular/material": "2.0.0-beta.2",

Using plain old [(selectedIndex)] does not work for me. Regardless of what it is set to the tab starts on the first tab. Right now have a hacky way of getting it done with a timeout that looks terrible.

setTimeout(() => {
switch (self.tabName) {
case 'default': self.tabGroup.selectedIndex = 0; break;
case 'othertab': self.tabGroup.selectedIndex = 1; break;
case 'othertab2': self.tabGroup.selectedIndex = 2; break;
case 'othertab3': self.tabGroup.selectedIndex = 3; break;
case 'othertab4': self.tabGroup.selectedIndex = 4; break;
}
}, 1000)

Why would my selected index binding not work the way you describe?

@AlanCrevon
Copy link

@PTC-JoshuaMatthews : Not sure what you are trying to do.

Here, my component has a class property selectedIndex : number = 0, which can be modified by any function such as :

selectNextTab(){
    this.selectedIndex++;
}

Then, my template uses <md-tab-group [(selectedIndex)]="selectedIndex">...</md-tab-group>

I hope it will help you :)

@PTC-JoshuaMatthews
Copy link

@AlanCrevon I am just demonstrating what I have to go through to use selectedIndex. I can set it after waiting for the control to instantiate (with the timeout) through a ViewChild instance. Binding to it the way you are describing is not working for me, the control ignores it.

@AlanCrevon
Copy link

@PTC-JoshuaMatthews sorry mate. Don't know how to help, then. :/

@walhow
Copy link

walhow commented Apr 11, 2018

Would it be possible to get the material documentation (link below) updated for tabs, to include an example of programmatically setting the selected index? The plunkr referenced above no longer works.

https://material.angular.io/components/tabs/examples

@Sangameshwarpuramwar
Copy link

When a selection is made, it may be on a new tab. Often we'll see someone add a tab to their list of tabs and immediately want to select it. In this case, we want to have it animate it in from the left or right. Went through many iterations until I figured out how to do this. The difficult part is that the selectedIndex setter is handled by angular before the view's tabs are updated.

is this issue fixed?

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants