Skip to content

Commit 23d7d50

Browse files
robotdanscottgonzalez
authored andcommitted
Button: Remove ui-state-active when disabling buttons
Fixes #9602 Closes gh-1151
1 parent 712ac17 commit 23d7d50

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

tests/unit/button/button_options.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,41 @@ test("disabled, null", function() {
3838
deepEqual(true, $("#radio02").prop("disabled"), "element is not disabled");
3939
});
4040

41+
test( "disabled, ui-state-active is removed unless checkbox or radio", function() {
42+
expect( 12 );
43+
var elements = [
44+
$( "<input type='button'>" ),
45+
$( "<button></button>" ),
46+
$( "<a></a>" ),
47+
$( "<div></div>" ),
48+
$( "<input type='checkbox' id='checkbox' checked><label for='checkbox'></label>" ),
49+
$( "<input type='radio' id='radio' checked><label for='radio'></label>" )
50+
];
51+
52+
$.each( elements, function() {
53+
var element = $( this ).first().button(),
54+
buttonElement = element.button( "widget" ),
55+
elementType = element.prop( "nodeName" ).toLowerCase();
56+
57+
if ( element.is( "input" ) ) {
58+
elementType += ":" + element.attr( "type" );
59+
}
60+
61+
element.trigger( "mousedown" );
62+
ok( buttonElement.hasClass( "ui-state-active" ),
63+
"[" + elementType + "] has ui-state-active class after mousedown." );
64+
65+
element.button( "disable" );
66+
if ( element.is( "[type=checkbox], [type=radio]" ) ) {
67+
ok( buttonElement.hasClass( "ui-state-active" ),
68+
"Disabled [" + elementType + "] has ui-state-active class." );
69+
} else {
70+
ok( !buttonElement.hasClass( "ui-state-active" ),
71+
"Disabled [" + elementType + "] does not have ui-state-active class." );
72+
}
73+
});
74+
});
75+
4176
test("text false without icon", function() {
4277
expect( 1 );
4378
$("#button").button({

ui/button.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,11 @@ $.widget( "ui.button", {
260260
this.widget().toggleClass( "ui-state-disabled", !!value );
261261
this.element.prop( "disabled", !!value );
262262
if ( value ) {
263-
this.buttonElement.removeClass( "ui-state-focus" );
263+
if ( this.type === "checkbox" || this.type === "radio" ) {
264+
this.buttonElement.removeClass( "ui-state-focus" );
265+
} else {
266+
this.buttonElement.removeClass( "ui-state-focus ui-state-active" );
267+
}
264268
}
265269
return;
266270
}

0 commit comments

Comments
 (0)