Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Dynamic nested sidenav created from JSON object is collapsing all accordions when a nested accordion is clicked.

AgentEnder free asked 4 years ago


Expected behavior

Clicking a nested tab should expand it, not collapse the above tab.

Actual behavior

Clicking the nested tab collapses its parent, causing its contents to never be seen. This is only occurring from the dynamic one, I can get static accordions to work but my use case requires the JSON object.

Resources (screenshots, code snippets etc.)

This is the template code for the dynamic menu

<ng-template #LinkGroupArrayRenderer let-groups>
    <ng-container *ngFor="let group of groups">
        <ul>
            <mdb-accordion>
                <ng-container *ngTemplateOutlet="
                    LinkGroupRenderer; 
                    context: {$implicit: group}"
                ></ng-container>
            </mdb-accordion>
        </ul>
     </ng-container>
 </ng-template>

 <ng-template #LinkGroupRenderer let-group>
     <mdb-accordion-item [customClass]="'ml-2'">
         <mdb-accordion-item-head>
             {{group.Heading}}
         </mdb-accordion-item-head>
         <mdb-accordion-item-body>
             <ng-container *ngIf="group.Subgroups && group.Subgroups.length">
                 <ng-container *ngTemplateOutlet="
                     LinkGroupArrayRenderer; 
                     context: {$implicit: group.Subgroups}">
                  </ng-container>
              </ng-container>
          <ng-container *ngFor="let link of group.Links">
               <li>
                   <a [href]="link.href" [title]="link.title">
                       {{link.title}}
                   </a>
               </li>
         </ng-container>
      </mdb-accordion-item-body>
   </mdb-accordion-item>
</ng-template>

This is the example JSON object:

export let clubLinks: LinkGroup = {
    Subgroups: [
        {
            Heading: 'Example Subsection',
            Links: [
                {
                    title: 'Example Link 1',
                    href: '#'
                },
                {
                    title: 'Example Link 2',
                    href: '#'
                }
            ]
        },
    ],
    Links: [
        {
            title: 'Example Link 3',
            href: '#'
        },
        {
            title: 'Example Link 4',
            href: '#'
        }
    ]
};

And finally, here is the code that works when I ran through the template logic by hand

    <mdb-accordion-item [customClass]="'ml-2'">
    <mdb-accordion-item-head>
        BLANK
    </mdb-accordion-item-head>
    <mdb-accordion-item-body>
        <ul>
            <mdb-accordion>
                <mdb-accordion-item [customClass]="'ml-2'">
                    <mdb-accordion-item-head>
                        Example Subsection
                    </mdb-accordion-item-head>
                    <mdb-accordion-item-body>
                        <li><a [href]="#" [title]="Example Link 1">{{Example link 1}}</a></li>
                        <li><a [href]="#" [title]="Example Link 2">{{Example link 2}}</a></li>
                    </mdb-accordion-item-body>
                </mdb-accordion-item>
            </mdb-accordion>
        </ul>
        <li><a [href]="#" [title]="Example Link 3">{{Example link 3}}</a></li>
        <li><a [href]="#" [title]="Example Link 4">{{Example link 4}}</a></li>
    </mdb-accordion-item-body>
</mdb-accordion-item>

Arkadiusz Idzikowski staff commented 4 years ago

Could you send a simple demo on which we will be able to reproduce this problem to a.idzikowski@mdbootstrap.com? It will be much easier to find the cause of this problem.


AgentEnder free commented 4 years ago

Hey Arkadiusz, I just sent the code your way. Sorry for the delay, caught me after I had left for the weekend.


Arkadiusz Idzikowski staff commented 4 years ago

Thank you for the demo app.

Please try to remove the [multiple]="false" input from the main mdb-accordion component and let me know if that helped.


AgentEnder free commented 4 years ago

That works as a workaround, but should not be required nor a long term fix seeing as that allows multiple sections of the top level accordion to open at once.

Seeing as the hand-ran version of the template logic works fine, is this a bug caused by the ng-container's and templates?


Arkadiusz Idzikowski staff commented 4 years ago

We still need to find the cause of the problem. We will let you know when the fix will be available.



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Opened

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 8.8.0
  • Device: Desktop
  • Browser: Chrome
  • OS: Win10
  • Provided sample code: No
  • Provided link: No