Skip to content

Commit 427f3d4

Browse files
kborchersscottgonzalez
authored andcommitted
Button: Don't fire click/change events if mouse was dragged during click of toggle (checkbox/radio) button. Fixed #6970 - Button state inconsistencies after (accidental) drag-clicking the button.
(cherry picked from commit a69a178)
1 parent 16b4ffb commit 427f3d4

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

ui/jquery.ui.button.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
(function( $, undefined ) {
1515

16-
var lastActive,
16+
var lastActive, startXPos, startYPos, clickDragged,
1717
baseClasses = "ui-button ui-widget ui-state-default ui-corner-all",
1818
stateClasses = "ui-state-hover ui-state-active ",
1919
typeClasses = "ui-button-icons-only ui-button-icon-only ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary ui-button-text-only",
@@ -111,21 +111,44 @@ $.widget( "ui.button", {
111111

112112
if ( toggleButton ) {
113113
this.element.bind( "change.button", function() {
114+
if ( clickDragged ) {
115+
return;
116+
}
114117
self.refresh();
115118
});
119+
// if mouse moves between mousedown and mouseup (drag) set clickDragged flag
120+
// prevents issue where button state changes but checkbox/radio checked state
121+
// does not in Firefox (see ticket #6970)
122+
this.buttonElement
123+
.bind( "mousedown.button", function( event ) {
124+
if ( options.disabled ) {
125+
return;
126+
}
127+
clickDragged = false;
128+
startXPos = event.pageX;
129+
startYPos = event.pageY;
130+
})
131+
.bind( "mouseup.button", function( event ) {
132+
if ( options.disabled ) {
133+
return;
134+
}
135+
if ( startXPos !== event.pageX || startYPos !== event.pageY ) {
136+
clickDragged = true;
137+
}
138+
});
116139
}
117140

118141
if ( this.type === "checkbox" ) {
119142
this.buttonElement.bind( "click.button", function() {
120-
if ( options.disabled ) {
143+
if ( options.disabled || clickDragged ) {
121144
return false;
122145
}
123146
$( this ).toggleClass( "ui-state-active" );
124147
self.buttonElement.attr( "aria-pressed", self.element[0].checked );
125148
});
126149
} else if ( this.type === "radio" ) {
127150
this.buttonElement.bind( "click.button", function() {
128-
if ( options.disabled ) {
151+
if ( options.disabled || clickDragged ) {
129152
return false;
130153
}
131154
$( this ).addClass( "ui-state-active" );

0 commit comments

Comments
 (0)