From 601e252074eedf89de9cb080db9c463a4b67ba77 Mon Sep 17 00:00:00 2001 From: Jacob Thornton Date: Mon, 27 Aug 2012 20:58:51 -0700 Subject: fix for #4761 --- js/bootstrap-button.js | 2 +- js/tests/unit/bootstrap-button.js | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/bootstrap-button.js b/js/bootstrap-button.js index 702198f6d0..a0ab0bfad5 100644 --- a/js/bootstrap-button.js +++ b/js/bootstrap-button.js @@ -51,7 +51,7 @@ } Button.prototype.toggle = function () { - var $parent = this.$element.parent('[data-toggle="buttons-radio"]') + var $parent = this.$element.closest('[data-toggle="buttons-radio"]') $parent && $parent .find('.active') diff --git a/js/tests/unit/bootstrap-button.js b/js/tests/unit/bootstrap-button.js index 03c4a8e9d5..b5d0834999 100644 --- a/js/tests/unit/bootstrap-button.js +++ b/js/tests/unit/bootstrap-button.js @@ -62,7 +62,7 @@ $(function () { ok(btn.hasClass('active'), 'btn has class active') }) - test("should toggle active when btn children are clicked within btn-group", function () { + test("should toggle active when btn children are clicked within btn-group", function () { var btngroup = $('
') , btn = $('') , inner = $('') @@ -74,4 +74,23 @@ $(function () { ok(btn.hasClass('active'), 'btn has class active') }) + test("should check for closest matching toggle", function () { + var group = $("
") + , btn1 = $("") + , btn2 = $("") + , wrap = $("
") + + wrap.append(btn1, btn2) + + group + .append(wrap) + .appendTo($('#qunit-fixture')) + + ok(btn1.hasClass('active'), 'btn1 has active class') + ok(!btn2.hasClass('active'), 'btn2 does not have active class') + btn2.click() + ok(!btn1.hasClass('active'), 'btn1 does not have active class') + ok(btn2.hasClass('active'), 'btn2 has active class') + }) + }) \ No newline at end of file -- cgit v1.2.3