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

Collapse Parent Grouping does not work inside a parent container with a "collapse" class #34850

Closed
BenjaminWKI opened this issue Aug 31, 2021 · 9 comments · Fixed by #34951
Closed
Labels
Projects

Comments

@BenjaminWKI
Copy link

BenjaminWKI commented Aug 31, 2021

Using Bootstrap 5.1 with my demonstration code below, the grouped "Child 1" and "Child 2" accordions refuse to hide the other when one is being opened.
The moment you remove the "collapse" class from the "parentContent" div container, the grouping works.

https://codepen.io/BenjaminWKI/pen/rNwxbBO

@GeoSot
Copy link
Member

GeoSot commented Aug 31, 2021

@BenjaminWKI please move this code into a code pen example and attach the link here

@GeoSot
Copy link
Member

GeoSot commented Sep 1, 2021

Thank you for transferring it.
I took up a look and seems that if you remove the second line <div class="accordion-item"> (and the closing tag) it works fine

Try the snippet below

<div id="parentGroup" class="accordion">

        <div id="parentHeader" class="accordion-header">
            <a href="#parentContent" data-bs-toggle="collapse" role="button" class="accordion-toggle">Parent</a>
        </div>
        <div id="parentContent" class="accordion-collapse collapse" aria-labelledby="parentHeader" data-bs-parent="#parentGroup">
            <div class="accordion-body">
                <div id="childGroup" class="accordion">
                    <div class="accordion-item">
                        <div id="childHeader1" class="accordion-header">
                            <a href="#childContent1" data-bs-toggle="collapse" role="button" class="accordion-toggle">Child 1</a>
                        </div>
                        <div id="childContent1" class="accordion-collapse collapse" aria-labelledby="childHeader1" data-bs-parent="#childGroup">
                            <div class="card-body">
                                <ul class="list-group">
                                    <li class="list-group-item"><a id="#indexLink_slideID1" href="javascript:showSlide();">Slide 1</a></li>
                                    <li class="list-group-item"><a id="#indexLink_slideID2" href="javascript:showSlide();">Slide 2</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>

                    <div class="accordion-item">
                        <div id="childHeader2" class="accordion-header">
                            <a href="#childContent2" data-bs-toggle="collapse" role="button" class="accordion-toggle">Child 2</a>
                        </div>
                        <div id="childContent2" class="accordion-collapse collapse" aria-labelledby="childHeader2" data-bs-parent="#childGroup">
                            <div class="card-body">
                                <ul class="list-group">
                                    <li class="list-group-item"><a id="#indexLink_slideID3" href="javascript:showSlide();">Slide 3</a></li>
                                    <li class="list-group-item"><a id="#indexLink_slideID4" href="javascript:showSlide();">Slide 4</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

</div>

@BenjaminWKI
Copy link
Author

BenjaminWKI commented Sep 1, 2021

Hi GeoSot,
I've tried your snippet code and there is no change in its behaviour. Both Child 1 & Child 2 would stay open.
If anything, removing the first <div class="accordion-item"> broke the grouping even further.
Without that div, ... my earlier fix: to remove the "collapse" class from <div id="parentContent">, ... would result in the same broken behaviour.

@BenjaminWKI BenjaminWKI changed the title Collapse Parent Grouping Don't Work Nestled In Parent Container With .collapse Collapse Parent Grouping Does Not Work Nestled In Parent Container With .collapse Sep 1, 2021
@BenjaminWKI BenjaminWKI changed the title Collapse Parent Grouping Does Not Work Nestled In Parent Container With .collapse Collapse Parent Grouping does not work inside a parent container with a "collapse" class Sep 1, 2021
@Rezyan
Copy link

Rezyan commented Sep 3, 2021

Thank you for transferring it.
I took up a look and seems that if you remove the second line <div class="accordion-item"> (and the closing tag) it works fine

Try the snippet below

<div id="parentGroup" class="accordion">

        <div id="parentHeader" class="accordion-header">
            <a href="#parentContent" data-bs-toggle="collapse" role="button" class="accordion-toggle">Parent</a>
        </div>
        <div id="parentContent" class="accordion-collapse collapse" aria-labelledby="parentHeader" data-bs-parent="#parentGroup">
            <div class="accordion-body">
                <div id="childGroup" class="accordion">
                    <div class="accordion-item">
                        <div id="childHeader1" class="accordion-header">
                            <a href="#childContent1" data-bs-toggle="collapse" role="button" class="accordion-toggle">Child 1</a>
                        </div>
                        <div id="childContent1" class="accordion-collapse collapse" aria-labelledby="childHeader1" data-bs-parent="#childGroup">
                            <div class="card-body">
                                <ul class="list-group">
                                    <li class="list-group-item"><a id="#indexLink_slideID1" href="javascript:showSlide();">Slide 1</a></li>
                                    <li class="list-group-item"><a id="#indexLink_slideID2" href="javascript:showSlide();">Slide 2</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>

                    <div class="accordion-item">
                        <div id="childHeader2" class="accordion-header">
                            <a href="#childContent2" data-bs-toggle="collapse" role="button" class="accordion-toggle">Child 2</a>
                        </div>
                        <div id="childContent2" class="accordion-collapse collapse" aria-labelledby="childHeader2" data-bs-parent="#childGroup">
                            <div class="card-body">
                                <ul class="list-group">
                                    <li class="list-group-item"><a id="#indexLink_slideID3" href="javascript:showSlide();">Slide 3</a></li>
                                    <li class="list-group-item"><a id="#indexLink_slideID4" href="javascript:showSlide();">Slide 4</a></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

</div>

Hi @GeoSot ,

I agree with @BenjaminWKI, there is a bug. The behavior of nested collapsibles with parents presents some bug since the v5 of Bootstrap.

I have created 2 Code Pen with your snippet to show you the problem:

@bewards
Copy link

bewards commented Sep 10, 2021

I was having a similar issue where I had an accordion inside a mobile collapsible hamburger menu. Every time I clicked on an accordion item, the dropdown menu would close. I was able to fix this on v5.0.1 by adding the show/hide event listeners to the accordion that took the event and stopped the propagation up to the dropdown menu. In v5.1.0+ this code no longer prevents the parent dropdown menu from triggering the "show/shown" events, and I'm seeing the problems stated above as well.

From the screenshot below, we can see that the Collapse JS code does not detect any "active" collapse items after the "Residential" button arrow is clicked, even though we can see that the first accordion item is active. I have this accordion set up within a "navbar.collapse" for mobile (opened via the hamburger button).
image

I'm not sure if this is an issue, but the ".collapse .collapse" selector returns the same elements as just ".collapse", as if it's not respecting the start location (accordion) and instead using the root document:
image

@bewards
Copy link

bewards commented Sep 10, 2021

@GeoSot I believe line 275 in collapse.js is missing the :scope pseudo-class at the start of ".collapse .collapse", as we want to be in the context of the parent accordion.

https://developer.mozilla.org/en-US/docs/Web/CSS/:scope

@GeoSot
Copy link
Member

GeoSot commented Sep 10, 2021

@bewards Many Many thanks. You saved me some time of searching

@XhmikosR XhmikosR added this to To do in v5.1.2 via automation Sep 11, 2021
@bewards
Copy link

bewards commented Sep 14, 2021

@GeoSot what's the timeline around release v5.1.2? I couldn't find release timeframes anywhere and didn't know if it followed the typical 2 week sprints.

@GeoSot
Copy link
Member

GeoSot commented Sep 15, 2021

It would be a nice idea to follow the " typical 2 weeks sprints", however I do not have this knowledge too
CC @mdo for a better answer than mine 😃

v5.1.2 automation moved this from To do to Done Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
v5.1.2
  
Done
Development

Successfully merging a pull request may close this issue.

4 participants