Skip to content

Commit

Permalink
#530 remove a11yValuePattern and replace with a11yCreateAriaValueText
Browse files Browse the repository at this point in the history
  • Loading branch information
twant committed Oct 2, 2019
1 parent 90fb4c4 commit b365934
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions js/accessibility/AccessibleValueHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ define( require => {
const KeyboardUtil = require( 'SCENERY/accessibility/KeyboardUtil' );
const Node = require( 'SCENERY/nodes/Node' );
const Property = require( 'AXON/Property' );
const StringUtils = require( 'PHETCOMMON/util/StringUtils' );
const sun = require( 'SUN/sun' );
const SunConstants = require( 'SUN/SunConstants' );
const Util = require( 'DOT/Util' );
const Utterance = require( 'SCENERY_PHET/accessibility/Utterance' );
const utteranceQueue = require( 'SCENERY_PHET/accessibility/utteranceQueue' );
Expand Down Expand Up @@ -64,28 +62,12 @@ define( require => {
*/
initializeAccessibleValueHandler( valueProperty, rangeProperty, enabledProperty, options ) {

// ensure that the client does not set both a custom text pattern and a text creation function
assert && assert(
!( options.a11yValuePattern && options.a11yCreateAriaValueText ),
'cannot set both a11yValuePattern and a11yCreateAriaValueText in options'
);

// if rounding to keyboard step, keyboardStep must be defined so values aren't skipped and the slider
// doesn't get stuck while rounding to the nearest value, see https://github.com/phetsims/sun/issues/410
if ( assert && options.roundToStepSize ) {
assert( options.keyboardStep, 'rounding to keyboardStep, define appropriate keyboardStep to round to' );
}

// verify that a11yValuePattern includes SunConstants.VALUE_NAMED_PLACEHOLDER, and that is the only key in the pattern
if ( assert && options.a11yValuePattern ) {
assert( options.a11yValuePattern.match( /{{[^{}]+}}/g ).length === 1,
'a11yValuePattern only accepts a single \'value\' key'
);
assert( options.a11yValuePattern.indexOf( SunConstants.VALUE_NAMED_PLACEHOLDER ) >= 0,
'a11yValuePattern must contain a key of \'value\''
);
}

const defaults = {

// other
Expand All @@ -101,7 +83,6 @@ define( require => {
// TODO: this should be an enumeration, https://github.com/phetsims/gravity-force-lab-basics/issues/134
ariaOrientation: 'horizontal', // specify orientation, read by assistive technology

a11yValuePattern: SunConstants.VALUE_NAMED_PLACEHOLDER, // {string} if you want units or additional content, add to pattern
a11yDecimalPlaces: 0, // number of decimal places for the value when formatted and read by assistive technology

// {boolean} - Whether or not to round the value to a multiple of the keyboardStep. This will only round
Expand All @@ -126,8 +107,7 @@ define( require => {
a11yRepeatEqualValueText: true,

/**
* Custom aria-valuetext creation function, called when the valueProperty changes. Used in replacement of
* the simpler/easier option: a11yValuePattern.
* aria-valuetext creation function, called when the valueProperty changes.
* This string is read by AT every time the slider value changes.
* @type {Function}
* @param {number} formattedValue - mapped value fixed to the provided decimal places
Expand Down Expand Up @@ -258,9 +238,6 @@ define( require => {
// @private {function}
this.a11yMapValue = options.a11yMapValue;

// @private {function}
this.a11yValuePattern = options.a11yValuePattern;

// @private {function}
this.a11yCreateAriaValueText = options.a11yCreateAriaValueText;

Expand Down Expand Up @@ -342,11 +319,8 @@ define( require => {
updateAriaValueText( oldPropertyValue ) {
const formattedValue = this.getA11yFormattedValue();

// create the final string from optional parameters. Only the valuePattern OR the create function can be
// specified (see above assertions).
let newAriaValueText = StringUtils.fillIn( this.a11yValuePattern, {
value: this.a11yCreateAriaValueText( formattedValue, this._valueProperty.value, oldPropertyValue )
} );
// create the dynamic aria-valuetext from a11yCreateAriaValueText.
let newAriaValueText = this.a11yCreateAriaValueText( formattedValue, this._valueProperty.value, oldPropertyValue );

if ( this._a11yRepeatEqualValueText && newAriaValueText === this.ariaValueText ) {

Expand Down

0 comments on commit b365934

Please sign in to comment.