aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna <[email protected]>2017-04-26 19:46:05 +0300
committerJohann-S <[email protected]>2017-04-26 18:46:05 +0200
commit33715a73d2eae3865cb4c1e0a13d1da4b6aeb278 (patch)
tree2b0b8dcdf2902e1bbf636deee69db92dec10ed8d
parentab39defe74914109df164c823af927de68320d55 (diff)
downloadbootstrap-33715a73d2eae3865cb4c1e0a13d1da4b6aeb278.tar.xz
bootstrap-33715a73d2eae3865cb4c1e0a13d1da4b6aeb278.zip
Fix Toggle buttons don't honor [disabled] or .disabled
-rw-r--r--js/src/button.js6
-rw-r--r--js/tests/unit/button.js17
2 files changed, 23 insertions, 0 deletions
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 = ' <div class="btn-group disabled" data-toggle="buttons" aria-disabled="true" disabled>'
+ + '<label class="btn btn-danger disabled" aria-disabled="true" disabled>'
+ + '<input type="checkbox" aria-disabled="true" autocomplete="off" disabled class="disabled"/>'
+ + '</label>'
+ + '</div>'
+ 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')
+ })
+
})