Skip to content

Commit

Permalink
optionally initialize Slider with a11y, see phetsims/scenery-phet#452
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegreenberg committed Jan 14, 2019
1 parent 34f093b commit 921d843
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions js/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ define( function( require ) {
enabledPropertyOptions: null, // {Object} options applied to the default enabledProperty
enabledRangeProperty: null, // {Property.<Range>|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
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 921d843

Please sign in to comment.