mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-12-07 06:14:24 +00:00
Spinner: Ignore mousewheel
events when not focused
Fixes #15139 Closes gh-1794
This commit is contained in:
parent
162377fba2
commit
a3b9129be1
@ -162,23 +162,39 @@ QUnit.test( "mouse click on up button, increases value not greater than max", fu
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "mousewheel on input", function( assert ) {
|
QUnit.test( "mousewheel on input", function( assert ) {
|
||||||
assert.expect( 4 );
|
var ready = assert.async();
|
||||||
|
assert.expect( 5 );
|
||||||
|
|
||||||
var element = $( "#spin" ).val( 0 ).spinner( {
|
var element = $( "#spin" ).val( 0 ).spinner( {
|
||||||
step: 2
|
step: 2
|
||||||
} );
|
} );
|
||||||
|
|
||||||
element.trigger( "mousewheel" );
|
element.simulate( "focus" );
|
||||||
assert.equal( element.val(), 0, "mousewheel event without delta does not change value" );
|
setTimeout( step1 );
|
||||||
|
|
||||||
element.trigger( "mousewheel", 1 );
|
function step1() {
|
||||||
assert.equal( element.val(), 2 );
|
element.trigger( "mousewheel" );
|
||||||
|
assert.equal( element.val(), 0, "mousewheel event without delta does not change value" );
|
||||||
|
|
||||||
element.trigger( "mousewheel", -0.2 );
|
element.trigger( "mousewheel", 1 );
|
||||||
assert.equal( element.val(), 0 );
|
assert.equal( element.val(), 2, "delta 1" );
|
||||||
|
|
||||||
element.trigger( "mousewheel", -15 );
|
element.trigger( "mousewheel", -0.2 );
|
||||||
assert.equal( element.val(), -2 );
|
assert.equal( element.val(), 0, "delta -0.2" );
|
||||||
|
|
||||||
|
element.trigger( "mousewheel", -15 );
|
||||||
|
assert.equal( element.val(), -2, "delta -15" );
|
||||||
|
|
||||||
|
element.simulate( "blur" );
|
||||||
|
setTimeout( step2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
function step2() {
|
||||||
|
element.trigger( "mousewheel", 1 );
|
||||||
|
assert.equal( element.val(), -2, "mousewheel when not focused" );
|
||||||
|
|
||||||
|
ready();
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
QUnit.test( "reading HTML5 attributes", function( assert ) {
|
QUnit.test( "reading HTML5 attributes", function( assert ) {
|
||||||
|
@ -140,9 +140,13 @@ $.widget( "ui.spinner", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mousewheel: function( event, delta ) {
|
mousewheel: function( event, delta ) {
|
||||||
if ( !delta ) {
|
var activeElement = $.ui.safeActiveElement( this.document[ 0 ] );
|
||||||
|
var isActive = this.element[ 0 ] === activeElement;
|
||||||
|
|
||||||
|
if ( !isActive || !delta ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !this.spinning && !this._start( event ) ) {
|
if ( !this.spinning && !this._start( event ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user