Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AccessibleValueHandler should not set a default aria-valuetext #681

Closed
zepumph opened this issue Jan 29, 2021 · 1 comment
Closed

AccessibleValueHandler should not set a default aria-valuetext #681

zepumph opened this issue Jan 29, 2021 · 1 comment
Assignees

Comments

@zepumph
Copy link
Member

zepumph commented Jan 29, 2021

I think this will be a better solution that what was originally done over in phetsims/ratio-and-proportion#283 (comment). I think that that bug was because we were just setting the valuenow as a string in the valuetext. That doesn't seem valuable at any rate. Let's see if we can get away with no valuetext unless it would add something more than just the value. Tagging @jessegreenberg.

@zepumph zepumph self-assigned this Jan 29, 2021
zepumph added a commit to phetsims/scenery that referenced this issue Jan 30, 2021
@zepumph
Copy link
Member Author

zepumph commented Jan 30, 2021

I used this patch to test this out, and it gave percents again, so I'm bailing. Closing

Index: sun/js/accessibility/AccessibleValueHandler.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/sun/js/accessibility/AccessibleValueHandler.js b/sun/js/accessibility/AccessibleValueHandler.js
--- a/sun/js/accessibility/AccessibleValueHandler.js	(revision 413bb8201c1aba1162cf6300c28c9b24af5cb3a3)
+++ b/sun/js/accessibility/AccessibleValueHandler.js	(date 1611960851311)
@@ -140,6 +140,7 @@
           /**
            * aria-valuetext creation function, called when the valueProperty changes.
            * This string is read by AT every time the slider value changes. This is often called the "object response"
+           * null means no aria-valuetext attribute will be set.
            * for this interaction.
            * @type {Function}
            * @param {number} pdomMappedValue - see
@@ -147,9 +148,9 @@
            * @param {number} previousValue - just the "oldValue" from the Property listener
            * @property {function} [reset] - if this function needs resetting, include a `reset` field on this function
            *                              to be called when the AccessibleValueHandler is reset.
-           * @returns {string} - aria-valuetext to be set to the primarySibling
+           * @returns {string|null} - aria-valuetext to be set to the primarySibling
            */
-          a11yCreateAriaValueText: toString, // by default make sure it returns a string
+          a11yCreateAriaValueText: null,
 
           /**
            * Create content for an alert that will be sent to the utteranceQueue when the user finishes interacting
@@ -293,7 +294,7 @@
         // @private {function}
         this.a11yMapPDOMValue = options.a11yMapPDOMValue;
 
-        // @private {function}
+        // @private {function|null} - when null, no aria-valuetext will be set
         this.a11yCreateAriaValueText = options.a11yCreateAriaValueText;
 
         // @private {Multilink}
@@ -378,21 +379,28 @@
        * @private
        */
       updateAriaValueText( oldPropertyValue ) {
-        const mappedValue = this.getMappedValue();
+
+        // A null creation function means that there should be no aria-valuetext
+        if ( this.a11yCreateAriaValueText === null ) {
+          this.ariaValueText = null;
+        }
+        else {
+          const mappedValue = this.getMappedValue();
 
-        // create the dynamic aria-valuetext from a11yCreateAriaValueText.
-        let newAriaValueText = this.a11yCreateAriaValueText( mappedValue, this._valueProperty.value, oldPropertyValue );
-        assert && assert( typeof newAriaValueText === 'string' );
+          // create the dynamic aria-valuetext from a11yCreateAriaValueText.
+          let newAriaValueText = this.a11yCreateAriaValueText( mappedValue, this._valueProperty.value, oldPropertyValue );
+          assert && assert( typeof newAriaValueText === 'string' );
 
-        // Make sure that the new aria-valuetext is different from the previous one, so that if they are the same
-        // the screen reader will still read the new text - adding a hairSpace registers as a new string, but the
-        // screen reader won't read that character.
-        const hairSpace = '\u200A';
-        if ( this._a11yRepeatEqualValueText && this.ariaValueText && newAriaValueText === this.ariaValueText.replace( new RegExp( hairSpace, 'g' ), '' ) ) {
-          newAriaValueText = this.ariaValueText + hairSpace;
-        }
+          // Make sure that the new aria-valuetext is different from the previous one, so that if they are the same
+          // the screen reader will still read the new text - adding a hairSpace registers as a new string, but the
+          // screen reader won't read that character.
+          const hairSpace = '\u200A';
+          if ( this._a11yRepeatEqualValueText && this.ariaValueText && newAriaValueText === this.ariaValueText.replace( new RegExp( hairSpace, 'g' ), '' ) ) {
+            newAriaValueText = this.ariaValueText + hairSpace;
+          }
 
-        this.ariaValueText = newAriaValueText;
+          this.ariaValueText = newAriaValueText;
+        }
       },
 
       /**
Index: ratio-and-proportion/js/create/view/MyChallengeAccordionBox.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/ratio-and-proportion/js/create/view/MyChallengeAccordionBox.js b/ratio-and-proportion/js/create/view/MyChallengeAccordionBox.js
--- a/ratio-and-proportion/js/create/view/MyChallengeAccordionBox.js	(revision cdf28502ec162f2fecaf99a5e1bd5be18979962a)
+++ b/ratio-and-proportion/js/create/view/MyChallengeAccordionBox.js	(date 1611960878332)
@@ -96,7 +96,6 @@
       center: Vector2.ZERO,
       accessibleName: ratioAndProportionStrings.a11y.leftValue,
       a11yDependencies: [ targetConsequentProperty ],
-      a11yCreateAriaValueText: ratioDescriber.getWordFromNumber,
       a11yCreateContextResponseAlert: () => ratioDescriber.getTargetRatioChangeAlert( targetAntecedentProperty.value, targetConsequentProperty.value )
     } );
     const leftRatioSelector = new VBox( {
@@ -115,7 +114,6 @@
       center: Vector2.ZERO,
       accessibleName: ratioAndProportionStrings.a11y.rightValue,
       a11yDependencies: [ targetAntecedentProperty ],
-      a11yCreateAriaValueText: ratioDescriber.getWordFromNumber,
       a11yCreateContextResponseAlert: () => ratioDescriber.getTargetRatioChangeAlert( targetAntecedentProperty.value, targetConsequentProperty.value )
     } );
     const rightRatioSelector = new VBox( {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant