diff --git a/js/gravity-force-lab-basics/view/GFLBMassControl.js b/js/gravity-force-lab-basics/view/GFLBMassControl.js index 572e749..40a4a8c 100644 --- a/js/gravity-force-lab-basics/view/GFLBMassControl.js +++ b/js/gravity-force-lab-basics/view/GFLBMassControl.js @@ -38,11 +38,12 @@ define( require => { * @param {Range} massRange * @param {String} labelContent - a11y, the content of the label for the mass control * @param {ISLCObjectEnum} thisObjectEnum + * @param {GFLBAlertManager} alertManager * @param {GFLBMassDescriber} massDescriber * @param {Tandem} tandem * @param {Object} [options] */ - constructor( titleString, valueProperty, massRange, labelContent, thisObjectEnum, + constructor( titleString, valueProperty, massRange, labelContent, thisObjectEnum, alertManager, massDescriber, tandem, options ) { options = merge( { @@ -55,6 +56,9 @@ define( require => { tandem: tandem.createTandem( 'titleText' ) } ); + // Keep track of the current mass between the start and end of an interaction to see if we should alert. + let currentMass = valueProperty.value; + const numberPicker = new NumberPicker( valueProperty, new Property( massRange ), { font: new PhetFont( 20 ), scale: 1.5, @@ -72,7 +76,20 @@ define( require => { // a11y pageKeyboardStep: BILLION_MULTIPLIER * 2, accessibleName: labelContent, - a11yCreateAriaValueText: () => massDescriber.getMassAndUnit( thisObjectEnum ) + a11yCreateAriaValueText: () => massDescriber.getMassAndUnit( thisObjectEnum ), + + // on end interaction, if alert a special alert if the mass started at the min/max and didnt' change. + a11yCreateValueChangeAlert: () => { + + // no change and at max or min + if ( currentMass === valueProperty.value && ( currentMass === massRange.max || currentMass === massRange.min ) ) { + return alertManager.alertMassMinMaxEdge( thisObjectEnum ); + } + return null; // regular mass changed alerts come from model changes + }, + startChange: () => { + currentMass = valueProperty.value; + } } ); const numberPickerLabel = new Text( billionKgString, { font: new PhetFont( { size: 14 } ), diff --git a/js/gravity-force-lab-basics/view/GFLBScreenView.js b/js/gravity-force-lab-basics/view/GFLBScreenView.js index 8873bb3..6a42f7b 100644 --- a/js/gravity-force-lab-basics/view/GFLBScreenView.js +++ b/js/gravity-force-lab-basics/view/GFLBScreenView.js @@ -95,7 +95,7 @@ define( require => { // initialize a11y describers and alert manager const positionDescriber = new GFLBPositionDescriber( model, mass1LabelString, mass2LabelString ); const forceDescriber = new GFLBForceDescriber( model, mass1LabelString, mass2LabelString, positionDescriber ); - const massDescriber = new GFLBMassDescriber( model ); + const massDescriber = new GFLBMassDescriber( model, forceDescriber ); const alertManager = new GFLBAlertManager( model, massDescriber, forceDescriber ); super( { @@ -172,10 +172,10 @@ define( require => { // mass controls const massControl1 = new GFLBMassControl( mass1String, model.object1.valueProperty, - GFLBConstants.MASS_RANGE, mass1ControlLabelString, OBJECT_ONE, + GFLBConstants.MASS_RANGE, mass1ControlLabelString, OBJECT_ONE, alertManager, massDescriber, tandem.createTandem( 'massControl1' ) ); const massControl2 = new GFLBMassControl( mass2String, model.object2.valueProperty, - GFLBConstants.MASS_RANGE, mass2ControlLabelString, OBJECT_TWO, + GFLBConstants.MASS_RANGE, mass2ControlLabelString, OBJECT_TWO, alertManager, massDescriber, tandem.createTandem( 'massControl2' ), { color: new Color( 255, 0, 0 ) } ); diff --git a/js/gravity-force-lab-basics/view/describers/GFLBMassDescriber.js b/js/gravity-force-lab-basics/view/describers/GFLBMassDescriber.js index 7400220..1cfa2f3 100644 --- a/js/gravity-force-lab-basics/view/describers/GFLBMassDescriber.js +++ b/js/gravity-force-lab-basics/view/describers/GFLBMassDescriber.js @@ -24,8 +24,9 @@ define( require => { /** * @param {GFLBModel} model + * @param {ForceDescriber} forceDescriber */ - constructor( model ) { + constructor( model, forceDescriber ) { const options = { object1Label: mass1LabelString, @@ -34,7 +35,7 @@ define( require => { formatMassValue: mass => StringUtils.fillIn( massBillionsPatternString, { mass: mass } ) }; - super( model, options ); + super( model, forceDescriber, options ); } }