Skip to content

Commit 3a282eb

Browse files
author
Carl Fürstenberg
committed
Button: Clear and set hover state when disabled; (Closes: #5295)
As there is a posibillity that an button is made disabled at the same time you are hovering above it, we need to make sure it's state are set to a ground state; The same accounts for if you are enabling a button while you are hovering above it; then it should enter ui-state-hover. Question still is if the same should be made for mousedown/mouseup events...
1 parent 135b180 commit 3a282eb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

ui/jquery.ui.button.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ $.widget( "ui.button", {
5858

5959
this._determineButtonType();
6060
this.hasTitle = !!this.buttonElement.attr( "title" );
61+
this.isHovering = false; // To be used if "enable" is called while mouse is hovering over a disabled button
6162

6263
var self = this,
6364
options = this.options,
@@ -77,6 +78,7 @@ $.widget( "ui.button", {
7778
.addClass( baseClasses )
7879
.attr( "role", "button" )
7980
.bind( "mouseenter.button", function() {
81+
self.isHovering = true;
8082
if ( options.disabled ) {
8183
return;
8284
}
@@ -86,6 +88,7 @@ $.widget( "ui.button", {
8688
}
8789
})
8890
.bind( "mouseleave.button", function() {
91+
self.isHovering = false;
8992
if ( options.disabled ) {
9093
return;
9194
}
@@ -230,6 +233,21 @@ $.widget( "ui.button", {
230233
},
231234

232235
_setOption: function( key, value ) {
236+
switch( key ) {
237+
case 'disabled':
238+
if( value ) {
239+
// There is a posibillity that the button is made disabled during hovering/clicking etc...
240+
// So to be on the safe side, we'll remove all state classes when calling disabled.
241+
this.element.removeClass( "ui-state-active ui-state-hover ui-state-focus" )
242+
} else {
243+
// We could be hovering (statically) over the disabled button and call "enable" on the button,
244+
// lets then mark it as in a hovering state.
245+
if( this.isHovering ) {
246+
this.element.addClass( "ui-state-hover" );
247+
}
248+
}
249+
break;
250+
}
233251
$.Widget.prototype._setOption.apply( this, arguments );
234252
if ( key === "disabled" ) {
235253
if ( value ) {

0 commit comments

Comments
 (0)