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

IgxTabs: Dynamically adding a tab is not working properly #9820

Closed
Timmeeeey opened this issue Jul 5, 2021 · 2 comments · Fixed by #9855
Closed

IgxTabs: Dynamically adding a tab is not working properly #9820

Timmeeeey opened this issue Jul 5, 2021 · 2 comments · Fixed by #9855
Assignees
Labels
🐛 bug Any issue that describes a bug ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged.

Comments

@Timmeeeey
Copy link

Description

If you dynamically add a tab which should be directly selected the tab content is displayed but the tab is not selected.

  • igniteui-angular version: 12.0.6
  • browser: Chrome 91

Steps to reproduce

<igx-tabs #tabGroup>
  <igx-tab-item *ngFor="let tab of tabs" [selected]="tab.selected">
    <igx-tab-header>
      {{tab.header}}
    </igx-tab-header>
    <igx-tab-content>
      content of {{tab.header}}
    </igx-tab-content>
  </igx-tab-item>
</igx-tabs>

<button (click)="addTab()">open new tab</button>
<p>selected index: {{tabGroup.selectedIndex}}</p>
tabs = [
  { header: 'Tab 1', selected: false },
  { header: 'Tab 2', selected: true }
];

addTab() {
  this.tabs.forEach(tab => (tab.selected = false));
  this.tabs.push({ header: 'Tab 3', selected: true });
}

click button to execute addTab()

Result

The content of the new tab is displayed but the tab doesn't get selected.
The selectedIndex of IgxTabs is set to -1;

Expected result

The new tab should be selected and the selectedIndex should be correctly updated.

Attachments

https://stackblitz.com/edit/angular-ivy-2wwec2

@Timmeeeey Timmeeeey added the 🐛 bug Any issue that describes a bug label Jul 5, 2021
@igdmdimitrov igdmdimitrov added 🛠️ status: in-development Issues and PRs with active development on them and removed 🆕 status: new labels Jul 6, 2021
@onlyexeption
Copy link
Contributor

Hello @Timmeeeey, I've changed your sample a bit so it can work properly. You can view it here - https://stackblitz.com/edit/angular-ivy-gkwjib?file=src/app/app.component.ts

Due to limitations, you need to use requestAnimationFrame in order to update the selectedIndex. Let me know if that works out for you!

@Timmeeeey
Copy link
Author

Hi @onlyexeption, yes this works for me thank you.

@gedinakova gedinakova added ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged. and removed 🛠️ status: in-development Issues and PRs with active development on them labels Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Any issue that describes a bug ✅ status: resolved Applies to issues that have pending PRs resolving them, or PRs that have already merged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants