Skip to content

Commit

Permalink
Button: use _hoverable for hover state management. Fixes #5295 - butt…
Browse files Browse the repository at this point in the history
…on doesn't remove hover state if they are disabled
  • Loading branch information
cgack authored and mikesherov committed Nov 12, 2012
1 parent 11687e4 commit 8e1ceba
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 11 additions & 0 deletions tests/unit/button/button_tickets.js
Expand Up @@ -5,6 +5,17 @@

module( "button: tickets" );

test( "#5295 - button does not remove hoverstate if disabled" , function() {
expect( 1 );
var btn = $("#button").button();
btn.hover( function() {
btn.button( "disable" );
});
btn.trigger( "mouseenter" );
btn.trigger( "mouseleave" );
ok( !btn.is( ".ui-state-hover") );
});

test( "#5946 - buttonset should ignore buttons that are not :visible", function() {
expect( 2 );
$( "#radio01" ).next().andSelf().hide();
Expand Down
7 changes: 4 additions & 3 deletions ui/jquery.ui.button.js
Expand Up @@ -70,21 +70,22 @@ $.widget( "ui.button", {
var that = this,
options = this.options,
toggleButton = this.type === "checkbox" || this.type === "radio",
hoverClass = "ui-state-hover" + ( !toggleButton ? " ui-state-active" : "" ),
activeClass = !toggleButton ? "ui-state-active" : "",
focusClass = "ui-state-focus";

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

this._hoverable( this.buttonElement );

this.buttonElement
.addClass( baseClasses )
.attr( "role", "button" )
.bind( "mouseenter" + this.eventNamespace, function() {
if ( options.disabled ) {
return;
}
$( this ).addClass( "ui-state-hover" );
if ( this === lastActive ) {
$( this ).addClass( "ui-state-active" );
}
Expand All @@ -93,7 +94,7 @@ $.widget( "ui.button", {
if ( options.disabled ) {
return;
}
$( this ).removeClass( hoverClass );
$( this ).removeClass( activeClass );
})
.bind( "click" + this.eventNamespace, function( event ) {
if ( options.disabled ) {
Expand Down

0 comments on commit 8e1ceba

Please sign in to comment.