Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/unit/button/button_tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,26 @@ test( "#6262 - buttonset not applying ui-corner to invisible elements", function
ok( set.find( "label:eq(2)" ).is( ".ui-button.ui-corner-right" ) );
});

test( "#7092 - button creation that requires a matching label does not find label in all cases", function() {
var group = $( "<span><label for='t7092a'/><input type='checkbox' id='t7092a'/></span>" );
group.find( "input:checkbox" ).button();
ok( group.find( "label" ).is( ".ui-button" ) );

group = $( "<input type='checkbox' id='t7092b'/><label for='t7092b'/>" );
group.filter( "input:checkbox" ).button();
ok( group.filter( "label" ).is( ".ui-button" ) );

group = $( "<span><input type='checkbox' id='t7092c'/></span><label for='t7092c'/>" );
group.find( "input:checkbox" ).button();
ok( group.filter( "label" ).is( ".ui-button" ) );

group = $( "<span><input type='checkbox' id='t7092d'/></span><span><label for='t7092d'/></span>" );
group.find( "input:checkbox" ).button();
ok( group.find( "label" ).is( ".ui-button" ) );

group = $( "<input type='checkbox' id='t7092e'/><span><label for='t7092e'/></span>" );
group.filter( "input:checkbox" ).button();
ok( group.find( "label" ).is( ".ui-button" ) );
});

})( jQuery );
12 changes: 10 additions & 2 deletions ui/jquery.ui.button.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,16 @@ $.widget( "ui.button", {
if ( this.type === "checkbox" || this.type === "radio" ) {
// we don't search against the document in case the element
// is disconnected from the DOM
this.buttonElement = this.element.parents().last()
.find( "label[for=" + this.element.attr("id") + "]" );
var ancestor = this.element.parents().last(),
labelSelector = "label[for=" + this.element.attr("id") + "]";
this.buttonElement = ancestor.find( labelSelector );
if ( !this.buttonElement.length ) {
ancestor = ancestor.length ? ancestor.siblings() : this.element.siblings();
this.buttonElement = ancestor.filter( labelSelector );
if ( !this.buttonElement.length ) {
this.buttonElement = ancestor.find( labelSelector );
}
}
this.element.addClass( "ui-helper-hidden-accessible" );

var checked = this.element.is( ":checked" );
Expand Down