]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Fix Toggle buttons don't honor [disabled] or .disabled
authorAnna <fpm.pankova@bsu.by>
Wed, 26 Apr 2017 16:46:05 +0000 (19:46 +0300)
committerJohann-S <johann.servoire@gmail.com>
Wed, 26 Apr 2017 16:46:05 +0000 (18:46 +0200)
js/src/button.js
js/tests/unit/button.js

index 6295d0db055b27106f94bd5ab5118d6658e36dc8..722fd489de6197d0141f674dd1ac13dfb15650df 100644 (file)
@@ -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')
           }
index abc04e10a90e435141562bf2834608c64eb36574..489d400a6ce7bd08101d82c9af7057f679ad1ceb 100644 (file)
@@ -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')
+  })
+
 })