From ab39defe74914109df164c823af927de68320d55 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Tue, 25 Apr 2017 03:32:14 -0400 Subject: Detach accordion from card without requiring 'data-children' --- js/src/collapse.js | 16 +++------- js/tests/unit/collapse.js | 76 +++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 71 insertions(+), 21 deletions(-) (limited to 'js') diff --git a/js/src/collapse.js b/js/src/collapse.js index dec272297..bf1c738f5 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -56,9 +56,8 @@ const Collapse = (($) => { } const Selector = { - ACTIVES : '.card > .show, .card > .collapsing', - DATA_TOGGLE : '[data-toggle="collapse"]', - DATA_CHILDREN : 'data-children' + ACTIVES : '.show, .collapsing', + DATA_TOGGLE : '[data-toggle="collapse"]' } @@ -78,20 +77,13 @@ const Collapse = (($) => { `[data-toggle="collapse"][href="#${element.id}"],` + `[data-toggle="collapse"][data-target="#${element.id}"]` )) + this._parent = this._config.parent ? this._getParent() : null if (!this._config.parent) { this._addAriaAndCollapsedClass(this._element, this._triggerArray) } - this._selectorActives = Selector.ACTIVES - if (this._parent) { - const childrenSelector = this._parent.hasAttribute(Selector.DATA_CHILDREN) ? this._parent.getAttribute(Selector.DATA_CHILDREN) : null - if (childrenSelector !== null) { - this._selectorActives = `${childrenSelector} > .show, ${childrenSelector} > .collapsing` - } - } - if (this._config.toggle) { this.toggle() } @@ -129,7 +121,7 @@ const Collapse = (($) => { let activesData if (this._parent) { - actives = $.makeArray($(this._parent).find(this._selectorActives)) + actives = $.makeArray($(this._parent).children().children(Selector.ACTIVES)) if (!actives.length) { actives = null } diff --git a/js/tests/unit/collapse.js b/js/tests/unit/collapse.js index 35fcf2108..2b9d0e58f 100644 --- a/js/tests/unit/collapse.js +++ b/js/tests/unit/collapse.js @@ -491,27 +491,85 @@ $(function () { }) QUnit.test('should allow accordion to use children other than card', function (assert) { - assert.expect(2) + assert.expect(4) var done = assert.async() - var accordionHTML = '
' + var accordionHTML = '
' + '
' + '' + '
' + '
' + '
' - + '' + + '' + '
' + '
' + '
' $(accordionHTML).appendTo('#qunit-fixture') - var $target = $('#linkTrigger') - $('#collapseOne').on('shown.bs.collapse', function () { - assert.ok($(this).hasClass('show')) - assert.ok(!$('#collapseTwo').hasClass('show')) - done() + 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')) }) - $target.trigger($.Event('click')) + $trigger.trigger($.Event('click')) + }) + + QUnit.test('should collapse accordion children but not nested accordion children', function (assert) { + assert.expect(9) + var done = assert.async() + $('
' + + '
' + + '' + + '
' + + '
' + + '
' + + '' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '
' + + '' + + '
' + + '
' + + '
').appendTo('#qunit-fixture') + var $trigger = $('#linkTrigger') + var $triggerTwo = $('#linkTriggerTwo') + var $nestedTrigger = $('#nestedLinkTrigger') + var $collapseOne = $('#collapseOne') + var $collapseTwo = $('#collapseTwo') + var $nestedCollapseOne = $('#nestedCollapseOne') + + + $collapseOne.one('shown.bs.collapse', function () { + assert.ok($collapseOne.hasClass('show'), '#collapseOne is shown') + assert.ok(!$collapseTwo.hasClass('show'), '#collapseTwo is not shown') + assert.ok(!$('#nestedCollapseOne').hasClass('show'), '#nestedCollapseOne is not shown') + $nestedCollapseOne.one('shown.bs.collapse', function () { + assert.ok($collapseOne.hasClass('show'), '#collapseOne is shown') + assert.ok(!$collapseTwo.hasClass('show'), '#collapseTwo is not shown') + assert.ok($nestedCollapseOne.hasClass('show'), '#nestedCollapseOne is shown') + $collapseTwo.one('shown.bs.collapse', function () { + assert.ok(!$collapseOne.hasClass('show'), '#collapseOne is not shown') + assert.ok($collapseTwo.hasClass('show'), '#collapseTwo is shown') + assert.ok($nestedCollapseOne.hasClass('show'), '#nestedCollapseOne is shown') + done() + }) + $triggerTwo.trigger($.Event('click')) + }) + $nestedTrigger.trigger($.Event('click')) + }) + $trigger.trigger($.Event('click')) }) QUnit.test('should not prevent event for input', function (assert) { -- cgit v1.2.3 From 33715a73d2eae3865cb4c1e0a13d1da4b6aeb278 Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 26 Apr 2017 19:46:05 +0300 Subject: Fix Toggle buttons don't honor [disabled] or .disabled --- js/src/button.js | 6 ++++++ js/tests/unit/button.js | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'js') diff --git a/js/src/button.js b/js/src/button.js index 6295d0db0..722fd489d 100644 --- a/js/src/button.js +++ b/js/src/button.js @@ -90,6 +90,12 @@ const Button = (($) => { } if (triggerChangeEvent) { + if (input.hasAttribute('disabled') || + rootElement.hasAttribute('disabled') || + input.classList.contains('disabled') || + rootElement.classList.contains('disabled')) { + return + } input.checked = !$(this._element).hasClass(ClassName.ACTIVE) $(input).trigger('change') } diff --git a/js/tests/unit/button.js b/js/tests/unit/button.js index abc04e10a..489d400a6 100644 --- a/js/tests/unit/button.js +++ b/js/tests/unit/button.js @@ -156,4 +156,21 @@ $(function () { assert.ok($btn2.is(':not([aria-pressed])'), 'label for nested radio input has not been given an aria-pressed attribute') }) + QUnit.test('should handle disabled attribute on non-button elements', function (assert) { + assert.expect(2) + var groupHTML = '
' + + '' + + '
' + var $group = $(groupHTML).appendTo('#qunit-fixture') + + var $btn = $group.children().eq(0) + var $input = $btn.children().eq(0) + + $btn.trigger('click') + assert.ok($btn.is(':not(.active)'), 'button did not become active') + assert.ok(!$input.is(':checked'), 'checkbox did not get checked') + }) + }) -- cgit v1.2.3 From db2db6cd0e654ddc3bfac5be5fbc93bf2bb3a674 Mon Sep 17 00:00:00 2001 From: Joyce Babu Date: Fri, 28 Apr 2017 19:01:35 +0530 Subject: Fix typo removeData for Tabs plugin Should remove `data` not `class` on dispose --- js/src/tab.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js') diff --git a/js/src/tab.js b/js/src/tab.js index 6f8187d17..c7bc520df 100644 --- a/js/src/tab.js +++ b/js/src/tab.js @@ -140,7 +140,7 @@ const Tab = (($) => { } dispose() { - $.removeClass(this._element, DATA_KEY) + $.removeData(this._element, DATA_KEY) this._element = null } -- cgit v1.2.3