Skip to content

Commit

Permalink
cherry pick from 31b65dd, see phetsims/coulombs-law#90
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg authored and mbarlow12 committed Dec 3, 2018
1 parent 0677cbd commit 34fa39f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion js/accessibility/AccessibleSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ define( function( require ) {
this.increasedEmitter = new Emitter();
this.decreasedEmitter = new Emitter();

// @private (a11y) - some browsers will receive `input` events when the user tabs away from the slider or
// on some key presses - if we receive a keydown event, we do not want the value to change twice, so we
// block input event after handling the keydown event
this.blockInput = false;

// @private - entries like { {number}: {boolean} }, key is range key code, value is whether it is down
this.rangeKeysDown = {};

Expand Down Expand Up @@ -345,6 +350,10 @@ define( function( require ) {
var code = event.keyCode;
this._shiftKey = event.shiftKey;

// if we receive a keydown event, we shouldn't handle any input events (which should only be provided
// directly by an assistive device)
this.blockInput = true;

if ( this._enabledProperty.get() ) {

// Prevent default so browser doesn't change input value automatically
Expand Down Expand Up @@ -458,7 +467,7 @@ define( function( require ) {
* @param {DOMEvent} event
*/
handleChange: function( event ) {
if ( this._enabledProperty.get() ) {
if ( this._enabledProperty.get() && !this.blockInput ) {

// don't handle changes if the element does not have focus - the browser may be trying to 'commit' a new
// value on blur that is evenly divisible by the step size, but we don't want that for AccessibleSlider
Expand Down

0 comments on commit 34fa39f

Please sign in to comment.