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

Component: Accordion do not reset selected active Tab on new dynamic tab data #16634

Closed
kievsash opened this issue Oct 24, 2024 · 2 comments · Fixed by #16838
Closed

Component: Accordion do not reset selected active Tab on new dynamic tab data #16634

kievsash opened this issue Oct 24, 2024 · 2 comments · Fixed by #16838
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Milestone

Comments

@kievsash
Copy link
Contributor

Describe the bug

Scenario:

  1. We create accordion with dynamic tabs (with ngFor)
  <button (click)="refreshData()">Reload data</button>
  <p-accordion [activeIndex]="0">
    <p-accordionTab [header]="tab.title" *ngFor="let tab of tabs">
      <p class="m-0">{{ tab.content }}</p>
    </p-accordionTab>
  </p-accordion>

and say press tab 3 to open it.
2. Then tabs array is changed but active tab is still tab 3 that creates bad UX (since data can be totally different).
3. No public method to drop it. Need to grab accordion instance and manually assign _activeIndex and tab.selected=false

Environment

Angular 18
Primeng 17

Reproducer

https://stackblitz.com/edit/lpeujv?file=src%2Fapp%2Faccordion-dynamic-demo.ts

Angular version

18.0.2

PrimeNG version

17.18.11

Build / Runtime

Angular CLI App

Language

TypeScript

Node version (for AoT issues node --version)

v20.9.0

Browser(s)

Chrome

Steps to reproduce the behavior

  1. Go to reproduce stackblizts
  2. Open tab 3 by clicking it
  3. Press Refresh button to recreate tabs array.
  4. Observe tab 3 still active

Expected behavior

  1. Either active tab should be 1st or all closed.
    Or
    Alternative - accordion instance public method (after grabbing instance with ViewChild) to reset active Tab
@kievsash kievsash added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Oct 24, 2024
@mertsincan mertsincan added Resolution: Help Wanted Issue or pull request requires extra help and feedback and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Nov 19, 2024
@mertsincan mertsincan added this to the Future milestone Nov 19, 2024
Copy link

Due to PrimeNG team's busy roadmap, this issue is available for anyone to work on. Make sure to reference this issue in your pull request. ✨ Thank you for your contribution! ✨

@kievsash
Copy link
Contributor Author

kievsash commented Nov 25, 2024

Here is the pr: #16838

cc @mertsincan

@mertsincan mertsincan added Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add and removed Resolution: Help Wanted Issue or pull request requires extra help and feedback labels Dec 6, 2024
@mertsincan mertsincan modified the milestones: Future, 17.18.13 Dec 6, 2024
@mertsincan mertsincan linked a pull request Dec 6, 2024 that will close this issue
mertsincan pushed a commit that referenced this issue Dec 6, 2024
* reset accordion ActiveTab

* revert package-lock.json changes
@mertsincan mertsincan moved this to Review in PrimeNG Dec 7, 2024
@mertsincan mertsincan moved this from Review to Done in PrimeNG Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Issue contains an enhancement related to a specific component. Additional functionality has been add
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants