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

Using AccordionTab inside of div or another element and not directly inside of an Accordion #13969

Closed
cetincakiroglu opened this issue Oct 27, 2023 · 0 comments
Assignees
Labels
Core Team Issue or pull request has been *opened* by a member of Core Team LTS-PORTABLE Issue's fix will be ported to supported LTS versions PRO Support Issue was reported by PRO User Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@cetincakiroglu
Copy link
Contributor

I want to create a custom directive for the accordion control. In the directive I want to listen to the active index change event and save the state of accordion tabs. The states are later reloaded when the user logs back in.
I am using this.accordion.activeIndexChange

This works fine when the accordion tab is added directly inside the accordion control like this:

<p-accordion>
    <p-accordionTab>

But if I add the tab inside a div or some other element then the accordion control does not see any of the tab and adds nothing to its tabsList property, basically the tabList is empty in this case, and because of that activeIndexChange or other functionality does not work. I believe the reason is that accordion control only look for direct descendants when creating the children list of type accordion tab,

<p-accordion>
    <div>
      <p-accordionTab>

The other problem it causes it is if you set multiple=false in which only one tab can be opened does not work, so you can put 3 tabs inside a tab inside accordion and say multiple=false and still be able to keep all three open.

This is the current code for creating the children
@ContentChildren(AccordionTab) tabList: QueryList | undefined;

I believe it should be this
@ContentChildren(AccordionTab, {descendants: true}) tabList: QueryList | undefined;

Live example: https://stackblitz.com/edit/jzsflk?file=src%2Fapp%2Fdemo%2Faccordion-basic-demo.html,src%2Fapp%2Fdemo%2Faccordion-basic-demo.ts

@cetincakiroglu cetincakiroglu added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working LTS-PORTABLE Issue's fix will be ported to supported LTS versions Core Team Issue or pull request has been *opened* by a member of Core Team PRO Support Issue was reported by PRO User labels Oct 27, 2023
@cetincakiroglu cetincakiroglu added this to the 16.7.0 milestone Oct 27, 2023
@cetincakiroglu cetincakiroglu self-assigned this Oct 27, 2023
@github-actions github-actions bot 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 27, 2023
@cetincakiroglu cetincakiroglu removed the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Core Team Issue or pull request has been *opened* by a member of Core Team LTS-PORTABLE Issue's fix will be ported to supported LTS versions PRO Support Issue was reported by PRO User Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

1 participant