Skip to content

Commit

Permalink
don't reset the HeaterCoolerNode slider when a key is released, reset…
Browse files Browse the repository at this point in the history
… on blur for alt input, see #853
  • Loading branch information
jessegreenberg committed Apr 25, 2024
1 parent 3e5e687 commit ff5a3f3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions js/HeaterCoolerFront.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Dimension2 from '../../dot/js/Dimension2.js';
import Range from '../../dot/js/Range.js';
import { Shape } from '../../kite/js/imports.js';
import optionize, { combineOptions } from '../../phet-core/js/optionize.js';
import { Color, Font, TColor, LinearGradient, Node, NodeOptions, Path, Text } from '../../scenery/js/imports.js';
import { Color, Font, LinearGradient, Node, NodeOptions, Path, TColor, Text } from '../../scenery/js/imports.js';
import { SliderOptions } from '../../sun/js/Slider.js';
import VSlider from '../../sun/js/VSlider.js';
import Tandem from '../../tandem/js/Tandem.js';
Expand Down Expand Up @@ -184,8 +184,12 @@ export default class HeaterCoolerFront extends Node {
thumbFill: options.thumbFill,
thumbSize: options.thumbSize,
thumbFillHighlighted: options.thumbFillHighlighted,
endDrag: () => {
if ( this.snapToZeroProperty.value || sliderIsCloseToZero() ) {
endDrag: event => {

// This only happens for mouse/touch events because it is a poor user experience to reset back to zero
// every time a key is released. For keyboard input, it is reset to zero when the slider loses focus.
const isFromPDOM = event && event.isFromPDOM();
if ( !isFromPDOM && this.snapToZeroProperty.value || sliderIsCloseToZero() ) {
setSliderToZero();
}
},
Expand All @@ -194,6 +198,11 @@ export default class HeaterCoolerFront extends Node {
tandem: options.tandem.createTandem( 'slider' )
}, options.sliderOptions ) );

// Set the slider back to zero when it loses focus.
this.slider.addInputListener( {
blur: setSliderToZero
} );

// Create the tick labels.
const labelOptions = {
font: options.labelFont,
Expand Down

0 comments on commit ff5a3f3

Please sign in to comment.