diff --git a/docs/4.0/components/collapse.md b/docs/4.0/components/collapse.md index e2ab5a01a..f6591ea8d 100644 --- a/docs/4.0/components/collapse.md +++ b/docs/4.0/components/collapse.md @@ -113,33 +113,6 @@ Using the [card]({{ site.baseurl }}/docs/{{ site.docs_version }}/components/card {% endexample %} -You can also create accordions with custom markup. Add the `data-children` attribute and specify a set of sibling elements to toggle (e.g., `.item`). Then, use the same attributes and classes as shown above for connecting toggles to their associated content. - -{% example html %} -
-
- - Toggle item - -
-

- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed pretium lorem non vestibulum scelerisque. Proin a vestibulum sem, eget tristique massa. Aliquam lacinia rhoncus nibh quis ornare. -

-
-
-
- -
-

- Donec at ipsum dignissim, rutrum turpis scelerisque, tristique lectus. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vivamus nec dui turpis. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. -

-
-
-
-{% endexample %} - ## Accessibility Be sure to add `aria-expanded` to the control element. This attribute explicitly conveys the current state of the collapsible element tied to the control to screen readers and similar assistive technologies. If the collapsible element is closed by default, the attribute on the control element should have a value of `aria-expanded="false"`. If you've set the collapsible element to be open by default using the `show` class, set `aria-expanded="true"` on the control instead. The plugin will automatically toggle this attribute on the control based on whether or not the collapsible element has been opened or closed (via JavaScript, or because the user triggered another control element also tied to the same collapsbile element). If the control element's HTML element is not a button (e.g., an `` or `
`), the attribute `role="button"` should be added to the element. diff --git a/js/src/collapse.js b/js/src/collapse.js index f4d140f27..eaad1be54 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -130,7 +130,11 @@ const Collapse = (($) => { let activesData if (this._parent) { - actives = $.makeArray($(this._parent).children().children(Selector.ACTIVES)) + actives = $.makeArray( + $(this._parent) + .find(Selector.ACTIVES) + .filter(`[data-parent="${this._config.parent}"]`) + ) if (!actives.length) { actives = null } diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index f20c0809c..337ec647b 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -516,12 +516,50 @@ $(function () { var done = assert.async() var accordionHTML = '
' + '
' - + '' - + '
' + + '' + + '
' + '
' + '
' - + '' - + '
' + + '' + + '
' + + '
' + + '
' + + $(accordionHTML).appendTo('#qunit-fixture') + var $trigger = $('#linkTrigger') + var $triggerTwo = $('#linkTriggerTwo') + var $collapseOne = $('#collapseOne') + var $collapseTwo = $('#collapseTwo') + $collapseOne.on('shown.bs.collapse', function () { + assert.ok($collapseOne.hasClass('show'), '#collapseOne is shown') + assert.ok(!$collapseTwo.hasClass('show'), '#collapseTwo is not shown') + $collapseTwo.on('shown.bs.collapse', function () { + assert.ok(!$collapseOne.hasClass('show'), '#collapseOne is not shown') + assert.ok($collapseTwo.hasClass('show'), '#collapseTwo is shown') + done() + }) + $triggerTwo.trigger($.Event('click')) + }) + $trigger.trigger($.Event('click')) + }) + + QUnit.test('should allow accordion to contain nested elements', function (assert) { + assert.expect(4) + var done = assert.async() + var accordionHTML = '
' + + '
' + + '
' + + '
' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + + '' + + '
' + + '
' + + '
' + '
' + '
' @@ -548,20 +586,20 @@ $(function () { var done = assert.async() $('
' + '
' - + '' - + '
' + + '' + + '
' + '
' + '
' - + '' - + '
' + + '' + + '
' + '
' + '
' + '
' + '
' + '
' + '
' - + '' - + '
' + + '' + + '
' + '
' + '
').appendTo('#qunit-fixture') var $trigger = $('#linkTrigger')