Permalink
Browse files

Fixes #2532458 - ButtonGroup properly handles nested labels

  • Loading branch information...
1 parent add13ae commit 866c1c77df7fdd31a05e8064accdc4af90a98348 @derek derek committed Jul 7, 2012
Showing with 28 additions and 4 deletions.
  1. +4 −4 src/button/js/group.js
  2. +24 −0 src/button/tests/button-group-test.js
View
@@ -106,12 +106,12 @@ Y.ButtonGroup = Y.extend(ButtonGroup, Y.Widget, {
* @private
*/
_handleClick: function(e){
- var buttons,
- clickedNode = e.target,
- group = this,
+ var group = this,
+ clickedNode = e.target.ancestor('.' + ButtonGroup.CLASS_NAMES.BUTTON, true),
type = group.get('type'),
selectedClass = ButtonGroup.CLASS_NAMES.SELECTED,
- isSelected = clickedNode.hasClass(selectedClass);
+ isSelected = clickedNode.hasClass(selectedClass),
+ buttons;
// TODO: Anything for 'push' groups?
@@ -157,6 +157,30 @@ YUI.add('button-group-test', function (Y) {
Assert.areSame(1, ButtonGroup.getSelectedButtons().length);
}
}));
+
+ // -- MISC ----------------------------------------------------------------
+ suite.add(new Y.Test.Case({
+ name: 'MISC',
+
+ setUp : function () {
+ Y.one("#container").setContent('<div id="group"><button><div class="yui3-button-label">Button A</div></button></div>');
+ this.ButtonGroup = new Y.ButtonGroup({
+ srcNode: '#group'
+ }).render();
+ },
+
+ tearDown: function () {
+ Y.one('#container').empty(true);
+ },
+
+ 'ButtonGroups should apply yui3-button-selected to anscestor button div, not the nested element that was clicked': function () {
+ var ButtonGroup = this.ButtonGroup;
+ var buttons = ButtonGroup.getButtons();
+
+ Y.one('#group>button>div').simulate('click');
+ Assert.areSame('button', Y.one('#group .yui3-button-selected').get('tagName').toLowerCase());
+ }
+ }));
Y.Test.Runner.add(suite);

0 comments on commit 866c1c7

Please sign in to comment.