Skip to content

Commit 85b5c5b

Browse files
cgackscottgonzalez
authored andcommitted
Button: use _hoverable for hover state management. Fixes #5295 - button doesn't remove hover state if they are disabled
(cherry picked from commit 8e1ceba)
1 parent e27195b commit 85b5c5b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

tests/unit/button/button_tickets.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55

66
module( "button: tickets" );
77

8+
test( "#5295 - button does not remove hoverstate if disabled" , function() {
9+
expect( 1 );
10+
var btn = $("#button").button();
11+
btn.hover( function() {
12+
btn.button( "disable" );
13+
});
14+
btn.trigger( "mouseenter" );
15+
btn.trigger( "mouseleave" );
16+
ok( !btn.is( ".ui-state-hover") );
17+
});
18+
819
test( "#5946 - buttonset should ignore buttons that are not :visible", function() {
920
expect( 2 );
1021
$( "#radio01" ).next().andSelf().hide();

ui/jquery.ui.button.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,22 @@ $.widget( "ui.button", {
7070
var that = this,
7171
options = this.options,
7272
toggleButton = this.type === "checkbox" || this.type === "radio",
73-
hoverClass = "ui-state-hover" + ( !toggleButton ? " ui-state-active" : "" ),
73+
activeClass = !toggleButton ? "ui-state-active" : "",
7474
focusClass = "ui-state-focus";
7575

7676
if ( options.label === null ) {
7777
options.label = (this.type === "input" ? this.buttonElement.val() : this.buttonElement.html());
7878
}
7979

80+
this._hoverable( this.buttonElement );
81+
8082
this.buttonElement
8183
.addClass( baseClasses )
8284
.attr( "role", "button" )
8385
.bind( "mouseenter" + this.eventNamespace, function() {
8486
if ( options.disabled ) {
8587
return;
8688
}
87-
$( this ).addClass( "ui-state-hover" );
8889
if ( this === lastActive ) {
8990
$( this ).addClass( "ui-state-active" );
9091
}
@@ -93,7 +94,7 @@ $.widget( "ui.button", {
9394
if ( options.disabled ) {
9495
return;
9596
}
96-
$( this ).removeClass( hoverClass );
97+
$( this ).removeClass( activeClass );
9798
})
9899
.bind( "click" + this.eventNamespace, function( event ) {
99100
if ( options.disabled ) {

0 commit comments

Comments
 (0)