@@ -210,10 +210,16 @@ class ReactSlider extends React.Component {
210
210
ariaLabel : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . arrayOf ( PropTypes . string ) ] ) ,
211
211
212
212
/**
213
- * aria-valuetext for screen-readers
213
+ * aria-valuetext for screen-readers.
214
+ * Can be a static string, or a function that returns a string.
215
+ * The function will be passed a single argument,
216
+ * an object with the following properties:
217
+ *
218
+ * - `index` {`number`} the index of the thumb
219
+ * - 'value' {`number` | `array`} the current value state
214
220
*/
215
221
// eslint-disable-next-line zillow/react/require-default-props
216
- ariaValuetext : PropTypes . string ,
222
+ ariaValuetext : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . func ] ) ,
217
223
218
224
/**
219
225
* Provide a custom render function for the track node.
@@ -841,31 +847,38 @@ class ReactSlider extends React.Component {
841
847
this . state . index === i ? this . props . thumbActiveClassName : ''
842
848
} `;
843
849
844
- return React . createElement (
845
- 'div' ,
846
- {
847
- ref : r => {
848
- this [ `thumb${ i } ` ] = r ;
849
- } ,
850
- key : `thumb${ i } ` ,
851
- className,
852
- style,
853
- onMouseDown : this . createOnMouseDown ( i ) ,
854
- onTouchStart : this . createOnTouchStart ( i ) ,
855
- onFocus : this . createOnKeyDown ( i ) ,
856
- tabIndex : 0 ,
857
- role : 'slider' ,
858
- 'aria-orientation' : this . props . orientation ,
859
- 'aria-valuenow' : this . state . value [ i ] ,
860
- 'aria-valuemin' : this . props . min ,
861
- 'aria-valuemax' : this . props . max ,
862
- 'aria-label' : Array . isArray ( this . props . ariaLabel )
863
- ? this . props . ariaLabel [ i ]
864
- : this . props . ariaLabel ,
865
- 'aria-valuetext' : this . props . ariaValuetext ,
850
+ const props = {
851
+ ref : r => {
852
+ this [ `thumb${ i } ` ] = r ;
866
853
} ,
867
- child
868
- ) ;
854
+ key : `thumb${ i } ` ,
855
+ className,
856
+ style,
857
+ onMouseDown : this . createOnMouseDown ( i ) ,
858
+ onTouchStart : this . createOnTouchStart ( i ) ,
859
+ onFocus : this . createOnKeyDown ( i ) ,
860
+ tabIndex : 0 ,
861
+ role : 'slider' ,
862
+ 'aria-orientation' : this . props . orientation ,
863
+ 'aria-valuenow' : this . state . value [ i ] ,
864
+ 'aria-valuemin' : this . props . min ,
865
+ 'aria-valuemax' : this . props . max ,
866
+ 'aria-label' : Array . isArray ( this . props . ariaLabel )
867
+ ? this . props . ariaLabel [ i ]
868
+ : this . props . ariaLabel ,
869
+ } ;
870
+
871
+ if ( this . props . ariaValuetext ) {
872
+ props [ 'aria-valuetext' ] =
873
+ typeof this . props . ariaValuetext === 'string'
874
+ ? this . props . ariaValuetext
875
+ : this . props . ariaValuetext ( {
876
+ value : this . state . value ,
877
+ index : i ,
878
+ } ) ;
879
+ }
880
+
881
+ return React . createElement ( 'div' , props , child ) ;
869
882
} ;
870
883
871
884
renderThumbs ( offset ) {
0 commit comments