Skip to content

Commit

Permalink
write out words for NumberPicker aria-valuetext, #283
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Dec 31, 2020
1 parent 31cc6cb commit e79314e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
27 changes: 27 additions & 0 deletions js/common/view/describers/RatioDescriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

import LinearFunction from '../../../../../dot/js/LinearFunction.js';
import Utils from '../../../../../dot/js/Utils.js';
import StringUtils from '../../../../../phetcommon/js/util/StringUtils.js';
import sceneryPhetStrings from '../../../../../scenery-phet/js/sceneryPhetStrings.js';
import ratioAndProportion from '../../../ratioAndProportion.js';
import ratioAndProportionStrings from '../../../ratioAndProportionStrings.js';
import RAPConstants from '../../RAPConstants.js';
Expand Down Expand Up @@ -34,6 +36,20 @@ const RATIO_FITNESS_STRINGS_LOWERCASE = [
ratioAndProportionStrings.a11y.ratio.lowercase.at
];

const NUMBER_TO_WORD = [
sceneryPhetStrings.zero,
sceneryPhetStrings.one,
sceneryPhetStrings.two,
sceneryPhetStrings.three,
sceneryPhetStrings.four,
sceneryPhetStrings.five,
sceneryPhetStrings.six,
sceneryPhetStrings.seven,
sceneryPhetStrings.eight,
sceneryPhetStrings.nine,
sceneryPhetStrings.ten
];

// an unclamped fitness of 0 should map to "somewhatCloseTo" region
const ZERO_FITNESS_REGION_INDEX = 4;

Expand Down Expand Up @@ -121,6 +137,17 @@ class RatioDescriber {
} );
}

/**
* @public
* @param {number} number
* @returns {string}
*/
getWordFromNumber( number ) {
assert && assert( Utils.isInteger( number ) );
assert && assert( NUMBER_TO_WORD.length > number );
return NUMBER_TO_WORD[ number ];
}

/**
* @public
* @param {number} antecedent
Expand Down
2 changes: 2 additions & 0 deletions js/create/view/MyChallengeAccordionBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class MyChallengeAccordionBox extends AccordionBox {
center: Vector2.ZERO,
accessibleName: ratioAndProportionStrings.a11y.leftValue,
a11yDependencies: [ targetConsequentProperty ],
a11yCreateAriaValueText: ratioDescriber.getWordFromNumber,
a11yCreateContextResponseAlert: () => ratioDescriber.getTargetRatioChangeAlert( targetAntecedentProperty.value, targetConsequentProperty.value )
} );
const leftRatioSelector = new VBox( {
Expand All @@ -114,6 +115,7 @@ class MyChallengeAccordionBox extends AccordionBox {
center: Vector2.ZERO,
accessibleName: ratioAndProportionStrings.a11y.rightValue,
a11yDependencies: [ targetAntecedentProperty ],
a11yCreateAriaValueText: ratioDescriber.getWordFromNumber,
a11yCreateContextResponseAlert: () => ratioDescriber.getTargetRatioChangeAlert( targetAntecedentProperty.value, targetConsequentProperty.value )
} );
const rightRatioSelector = new VBox( {
Expand Down

0 comments on commit e79314e

Please sign in to comment.