Skip to content

Button: remove ui-state-active on button disable. Fixed #9602 - ui-state-active remains after disable #1151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
35 changes: 35 additions & 0 deletions tests/unit/button/button_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,41 @@ test("disabled, null", function() {
deepEqual(true, $("#radio02").prop("disabled"), "element is not disabled");
});

test( "disabled, ui-state-active is removed unless checkbox or radio", function() {
expect( 12 );
var elements = [
$( "<input type='button'>" ),
$( "<button></button>" ),
$( "<a></a>" ),
$( "<div></div>" ),
$( "<input type='checkbox' id='checkbox' checked><label for='checkbox'></label>" ),
$( "<input type='radio' id='radio' checked><label for='radio'></label>" )
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is indented too much.


$.each( elements, function() {
var element = $( this ).first().button(),
buttonElement = element.button( "widget" ),
elementType = element.prop( "nodeName" ).toLowerCase();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blank line here.

if ( element.is( "input" ) ) {
elementType += ":" + element.attr( "type" );
}

element.trigger( "mousedown" );
ok( buttonElement.hasClass( "ui-state-active" ),
"[" + elementType + "] has ui-state-active class after mousedown." );

element.button( "disable" );
if ( element.is( "[type=checkbox], [type=radio]" ) ) {
ok( buttonElement.hasClass( "ui-state-active" ),
"Disabled [" + elementType + "] has ui-state-active class." );
} else {
ok( !buttonElement.hasClass( "ui-state-active" ),
"Disabled [" + elementType + "] does not have ui-state-active class." );
}
});
});

test("text false without icon", function() {
expect( 1 );
$("#button").button({
Expand Down
6 changes: 5 additions & 1 deletion ui/jquery.ui.button.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ $.widget( "ui.button", {
this.widget().toggleClass( "ui-state-disabled", !!value );
this.element.prop( "disabled", !!value );
if ( value ) {
this.buttonElement.removeClass( "ui-state-focus" );
if ( this.type === "checkbox" || this.type === "radio" ) {
this.buttonElement.removeClass( "ui-state-focus" );
} else {
this.buttonElement.removeClass( "ui-state-focus ui-state-active" );
}
}
return;
}
Expand Down