From aa510d891f9ab52cbcfde4f7a1b9ac69ed196acb Mon Sep 17 00:00:00 2001 From: Jesse Date: Mon, 17 May 2021 18:03:31 -0400 Subject: [PATCH] example of speaking full response, see https://github.com/phetsims/ratio-and-proportion/issues/381 --- js/common/view/describers/RatioDescriber.js | 16 ++++++++++++++++ js/create/view/MyChallengeAccordionBox.js | 17 +++++++++-------- ratio-and-proportion-strings_en.json | 6 ++++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/js/common/view/describers/RatioDescriber.js b/js/common/view/describers/RatioDescriber.js index 7efd8fcd..15f1b820 100644 --- a/js/common/view/describers/RatioDescriber.js +++ b/js/common/view/describers/RatioDescriber.js @@ -149,6 +149,22 @@ class RatioDescriber { } ); } + /** + * Get a description fragment describing the antecedent value to the consequent value, + * something like: + * "1 to 2" + * @public + * + * @param {number} antecedent + * @param {number} consequent + */ + getAntecedentToConsequentFragnemt( antecedent, consequent ) { + return StringUtils.fillIn( ratioAndProportionStrings.a11y.ratio.antecedentToConsequentPattern, { + targetAntecedent: antecedent, + targetConsequent: consequent + } ); + } + /** * @public * @param {number} antecedent diff --git a/js/create/view/MyChallengeAccordionBox.js b/js/create/view/MyChallengeAccordionBox.js index 3dd812af..b3b14ae1 100644 --- a/js/create/view/MyChallengeAccordionBox.js +++ b/js/create/view/MyChallengeAccordionBox.js @@ -155,33 +155,34 @@ class MyChallengeAccordionBox extends AccordionBox { const accordionBoxUtterance = new ActivationUtterance(); const accordionBoxVoicingUtterance = new ActivationUtterance(); - this.expandedProperty.lazyLink( expanded => { + this.expandedProperty.link( ( expanded, oldValue ) => { // strings containing responses used for Voicing - let contextResponse = ''; + let objectResponse = ''; let hintResponse = ''; if ( expanded ) { - contextResponse = ratioDescriber.getCurrentChallengeSentence( targetAntecedentProperty.value, targetConsequentProperty.value ); + objectResponse = ratioDescriber.getAntecedentToConsequentFragnemt( targetAntecedentProperty.value, targetConsequentProperty.value ); hintResponse = ratioAndProportionStrings.a11y.create.myChallengeExpandedHintText; accordionBoxUtterance.alert = ratioDescriber.getCurrentChallengeSentence( targetAntecedentProperty.value, targetConsequentProperty.value ); } else { - contextResponse = ratioAndProportionStrings.a11y.ratio.currentChallengeHidden; + objectResponse = ratioAndProportionStrings.a11y.ratio.hidden; hintResponse = ratioAndProportionStrings.a11y.create.myChallengeCollapsedHintText; accordionBoxUtterance.alert = ratioAndProportionStrings.a11y.ratio.currentChallengeHidden; } this.setButtonVoicingOptions( { - voicingContextResponse: contextResponse, + voicingObjectResponse: objectResponse, voicingHintResponse: hintResponse } ); - this.voicingSpeakButtonResponse( { utterance: accordionBoxVoicingUtterance } ); - phet.joist.sim.utteranceQueue.addToBack( accordionBoxUtterance ); - + if ( oldValue !== null ) { + this.voicingSpeakButtonResponse( { utterance: accordionBoxVoicingUtterance } ); + phet.joist.sim.utteranceQueue.addToBack( accordionBoxUtterance ); + } } ); Property.multilink( [ targetAntecedentProperty, targetConsequentProperty ], ( targetAntecedent, targetConsequent ) => { diff --git a/ratio-and-proportion-strings_en.json b/ratio-and-proportion-strings_en.json index 864098a3..853efc2f 100644 --- a/ratio-and-proportion-strings_en.json +++ b/ratio-and-proportion-strings_en.json @@ -540,9 +540,15 @@ "myChallenge": { "value": "My Challenge {{targetAntecedent}} to {{targetConsequent}}." }, + "antecedentToConsequentPattern": { + "value": "{{targetAntecedent}} to {{targetConsequent}}" + }, "myChallengeHidden": { "value": "My Challenge hidden." }, + "hidden": { + "value": "hidden" + }, "capitalized": { "at": { "value": "At"