Skip to content

Commit bf3c3d7

Browse files
authored
Merge pull request #125 from atlidohop/feat/accessibility-aria-label-support
Accessibility: Support aria-labels
2 parents 1b3ef9d + a783e5d commit bf3c3d7

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ Callback called only after moving a handle has ended or when a new value is set
145145

146146
Callback called when the the slider is clicked (handle or bars). Receives the value at the clicked position as argument.
147147

148+
##### ariaLabel {oneOfType([string, arrayOf(string)])}
149+
150+
aria-label for screen-readers to apply to the handles.
151+
Use an array for more than one handle.
152+
The length of the array must match the number of handles in the value array.
153+
154+
##### ariaValuetext {string}
155+
156+
aria-valuetext for screen-readers
157+
148158
### Methods
149159

150160
##### getValue

index.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,33 @@
131131
}
132132
}));
133133

134-
ReactDOM.render(Demo({defaultValue: 0, orientation: 'horizontal'}), document.getElementById('horizontal-1'));
134+
ReactDOM.render(Demo({
135+
defaultValue: 0,
136+
orientation: 'horizontal',
137+
ariaLabel: 'This is a single handle',
138+
}), document.getElementById('horizontal-1'));
135139

136140
ReactDOM.render(Demo({
137141
defaultValue: [0, 100],
138142
orientation: 'horizontal',
139-
withBars: true
143+
withBars: true,
144+
ariaLabel: ['Lower handle', 'Upper handle'],
145+
ariaValuetext: 'Some arbitrary value',
140146
}), document.getElementById('horizontal-2'));
141147

142148
ReactDOM.render(Demo({
143149
defaultValue: [0, 50, 100],
144150
orientation: 'horizontal',
145-
withBars: true
151+
withBars: true,
152+
ariaLabel: ['Leftmost handle', 'Middle handle', 'Rightmost handle'],
146153
}), document.getElementById('horizontal-3'));
147154

148155
ReactDOM.render(Demo({
149156
defaultValue: [0, 50, 100],
150157
orientation: 'vertical',
151158
withBars: true,
152-
invert: true
159+
invert: true,
160+
ariaLabel: ['Lowest handle', 'Middle handle', 'Top handle'],
153161
}), document.getElementById('vertical'));
154162
</script>
155163
</body>

react-slider.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
return x != null && x.length === 1 ? x[0] : x;
4343
}
4444

45+
var isArray = Array.isArray || function(x) {
46+
return Object.prototype.toString.call(x) === '[object Array]';
47+
};
48+
4549
// undoEnsureArray(ensureArray(x)) === x
4650

4751
var ReactSlider = createReactClass({
@@ -749,6 +753,8 @@
749753
"aria-valuenow": this.state.value[i],
750754
"aria-valuemin": this.props.min,
751755
"aria-valuemax": this.props.max,
756+
"aria-label": isArray(this.props.ariaLabel) ? this.props.ariaLabel[i] : this.props.ariaLabel,
757+
"aria-valuetext": this.props.ariaValuetext,
752758
},
753759
child
754760
)

0 commit comments

Comments
 (0)