From 921d843b18d1d4e9be3ee5339a9dd3aa79fe87b8 Mon Sep 17 00:00:00 2001 From: Jesse Date: Mon, 14 Jan 2019 14:54:43 -0500 Subject: [PATCH] optionally initialize Slider with a11y, see phetsims/scenery-phet#452 --- js/Slider.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/js/Slider.js b/js/Slider.js index 460b2590..dff8e4e2 100644 --- a/js/Slider.js +++ b/js/Slider.js @@ -97,6 +97,9 @@ define( function( require ) { enabledPropertyOptions: null, // {Object} options applied to the default enabledProperty enabledRangeProperty: null, // {Property.|null} determine the portion of range that is enabled + // a11y - if false, Slider will not be keyboard navigable and have no representation in the PDOM + isAccessible: true, + // phet-io tandem: Tandem.required, phetioType: SliderIO @@ -262,9 +265,6 @@ define( function( require ) { }; this.enabledProperty.link( enabledObserver ); // must be unlinked in disposeSlider - // a11y - custom focus highlight that surrounds and moves with the thumb - this.focusHighlight = new FocusHighlightFromNode( thumb ); - // update thumb location when value changes var valueObserver = function( value ) { thumb.centerX = self.valueToPosition( value ); @@ -305,11 +305,18 @@ define( function( require ) { thumbInputListener.dispose(); }; - // mix accessible slider functionality into Slider - this.initializeAccessibleSlider( valueProperty, this.enabledRangeProperty, this.enabledProperty, - _.extend( {}, options, { - ariaOrientation: options.orientation - } ) ); + // a11y - custom focus highlight that surrounds and moves with the thumb, set outside of options.isAccessible + // check because some composite types that include Slider may use the focus highlight, regardless of whether or + // not it is accessible + this.focusHighlight = new FocusHighlightFromNode( thumb ); + + if ( options.isAccessible ) { + this.initializeAccessibleSlider( valueProperty, this.enabledRangeProperty, this.enabledProperty, + _.extend( {}, options, { + ariaOrientation: options.orientation + } + ) ); + } // support for binder documentation, stripped out in builds and only runs when ?binder is specified assert && phet.chipper.queryParameters.binder && InstanceRegistry.registerDataURL( 'sun', 'Slider', this );