accordion tabs are opened after dialog close
Describe the bug
Everything is written in https://github.com/primefaces/primeng/issues/9453
Environment
in issue https://github.com/primefaces/primeng/issues/9453
Reproducer
https://stackblitz.com/edit/primeng-dialog-accordion-problem-tqtn9k?file=package.json
Angular version
14.2.10
PrimeNG version
14.2.1
Build / Runtime
Angular CLI App
Language
TypeScript
Node version (for AoT issues node --version)
14.17.3
Browser(s)
All
Steps to reproduce the behavior
in issue https://github.com/primefaces/primeng/issues/9453
Expected behavior
in issue https://github.com/primefaces/primeng/issues/9453
I noticed something similar for DynamicDialog and Dialog in v15/v16 with Accordion and Panel. When the dynamic dialog is opened, all tabs are quickly expanded and then collapses after a few milliseconds.
When closing the dynamic dialog, all the tabs are re-expanded again before it disappears. It may be hard to see because it happens so quickly.
I was hoping the accordion would remain collapsed the entire time unless the user actually clicks the tabs.
Here is a forked example based off the DynamicDialog docs for v16, but I replaced p-table with p-accordion: https://stackblitz.com/edit/luvqct?file=src%2Fapp%2Fdemo%2Fproductlistdemo.ts
The error is still present in primeng v17.16.1. Using an accordion in a dialog leads to inconsistent behavior. When closing the dialog, the accordion expands all tabs for a few milliseconds before closing, and when reopening the dialog, the tabs are open. Checkout this simple example.
Issue also exists if you're using p-sidebar component. Opening a sidebar on the second attempt will open all the accordions.
Demo: https://stackblitz.com/edit/z4x4wd
Still happening with v17.18.0, it's so annoying
Le problème existe également si vous utilisez le composant p-sidebar. L'ouverture d'une barre latérale à la deuxième tentative ouvrira tous les accordéons.
Démo : https://stackblitz.com/edit/z4x4wd
I confirm bug with sidebar. How resolve this? I'm at version 17.18.4.
Le problème existe également si vous utilisez le composant p-sidebar. L'ouverture d'une barre latérale à la deuxième tentative ouvrira tous les accordéons. Démo : https://stackblitz.com/edit/z4x4wd
I confirm bug with sidebar. How resolve this? I'm at version 17.18.4.
for a work around I've used a skeleton loader with a setTimeout function. On hide, set the loader to true and on show set it to false after small amount of time allowing items to render properly inside the p-sidebar.
public onPanelClick(): void {
//we use signal in the template for the visible property that can be opened from x amount of places
this.myService.showSidebar();
setTimeout(() => {
this.loading = false;
}, 350);
}
public onHideSidebarClick(): void {
this.myService.hideSidebar();
this.loading = true;
}
This is still happening to me on angular 18.2.7 and primeng 17.18.9
for a p-accordion inside a p-dialog, when the dialog closes then opens again, all accordions inside it are fully expanded.
Here's an example, first time opening the dialog (looks good)
close the dialog then reopen it... all accordions are expanded! and the tiny arrow directions are all wrong!
I can confirm it's still happening in v18 of primeng as well
Still an issue in 18.0.2.
Also maybe related: When opening a popover after having closed it then the accordions inside will be wrongly expanded. Seems like popover caches its content, but there is something wrong in the de-/serialization of the accordion state? Not sure..
This problem still persists in prime ng 19 version.
My workaround (on v19.0.5) with the use of TailwindCSS, if it helps anyone:
<p-accordion [value]="1">
<p-accordion-panel [value]="1" class="!h-0 [&.p-accordionpanel-active]:!h-auto">
<p-accordion-content>
Content here
</p-accordion-content>
</p-accordion-panel>
</p-accordion>
Note: You'll lose the "smooth" closing animation, that's because the p-accordionpanel-active class is applied before the animation finishes and so the override !h-0 will take effect immediately. The opening animation still works.
v19.1.3: When I wrap my dialog content in <ng-template #content></ng-template> the accordion panel content is only visible for a short moment.
I wrote a small angular directive to hide the accordion panel content initially for a short moment as a temporary workaround. It does not help when closing the dialog, but it solves the very obvious layout shift when opening the dialog.
import { Directive, ElementRef, inject, OnInit } from '@angular/core'
@Directive({
selector: '[appFixAccordionPanelInDialog]',
host: { style: 'display: none' },
})
export class FixAccordionPanelInDialogDirective implements OnInit {
host = inject(ElementRef)
ngOnInit(): void {
setTimeout(() => (this.host.nativeElement.style.display = 'inherit'), 250)
}
}
<p-accordion-content appFixAccordionPanelInDialog>Content</p-accordion-content>
I am also experiencing this issue on v20.2
idem on v19