Skip to content

Commit 38a9dc9

Browse files
committed
Add support for ariaControls and fix ariaLabelledby not working
1 parent 1a31253 commit 38a9dc9

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ If accepting a single value, pass a number to `value` prop, i.e.:
7171
Property | Type | Description
7272
:-----------------------|:-----------------------------------|:----------------------------------
7373
ariaLabelledby |string |`aria-labelledby` attribute
74+
ariaControls |string |`aria-controls` attribute
7475
classNames |Object.<string> |CSS class names
7576
defaultValue |number | Object.<number> |Default value(s)
7677
disabled |boolean |Disabled or not

src/InputRange/InputRange.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ function renderSliders(inputRange) {
184184

185185
const slider = (
186186
<Slider
187+
ariaLabelledby={ inputRange.props.ariaLabelledby }
188+
ariaControls={ inputRange.props.ariaControls }
187189
classNames={ classNames }
188190
key={ key }
189191
maxValue={ maxValue }
@@ -575,6 +577,7 @@ export default class InputRange extends React.Component {
575577
* Accepted propTypes of InputRange
576578
* @static {Object}
577579
* @property {Function} ariaLabelledby
580+
* @property {Function} ariaControls
578581
* @property {Function} classNames
579582
* @property {Function} defaultValue
580583
* @property {Function} disabled
@@ -588,6 +591,7 @@ export default class InputRange extends React.Component {
588591
*/
589592
InputRange.propTypes = {
590593
ariaLabelledby: React.PropTypes.string,
594+
ariaControls: React.PropTypes.string,
591595
classNames: React.PropTypes.objectOf(React.PropTypes.string),
592596
defaultValue: maxMinValuePropType,
593597
disabled: React.PropTypes.bool,

src/InputRange/Slider.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export default class Slider extends React.Component {
160160

161161
<a
162162
aria-labelledby={ this.props.ariaLabelledby }
163+
aria-controls={ this.props.ariaControls }
163164
aria-valuemax={ this.props.maxValue }
164165
aria-valuemin={ this.props.minValue }
165166
aria-valuenow={ this.props.value }
@@ -181,6 +182,7 @@ export default class Slider extends React.Component {
181182
* Accepted propTypes of Slider
182183
* @static {Object}
183184
* @property {Function} ariaLabelledby
185+
* @property {Function} ariaControls
184186
* @property {Function} className
185187
* @property {Function} maxValue
186188
* @property {Function} minValue
@@ -192,6 +194,7 @@ export default class Slider extends React.Component {
192194
*/
193195
Slider.propTypes = {
194196
ariaLabelledby: React.PropTypes.string,
197+
ariaControls: React.PropTypes.string,
195198
classNames: React.PropTypes.objectOf(React.PropTypes.string),
196199
maxValue: React.PropTypes.number,
197200
minValue: React.PropTypes.number,

test/InputRange.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,4 +460,32 @@ describe('InputRange', () => {
460460
expect(onChangeComplete).not.toHaveBeenCalled();
461461
});
462462
});
463+
464+
describe('ariaLabelledby', () => {
465+
it('should call onChangeComplete if value has changed since the start of interaction', () => {
466+
inputRange = renderComponent(
467+
<InputRange ariaLabelledby="foobar" maxValue={20} minValue={0} value={values} onChange={onChange} />
468+
);
469+
470+
const slider = ReactDOM.findDOMNode(inputRange.refs.sliderMax);
471+
const handle = slider.querySelector('a');
472+
const ariaLabelledby = handle.getAttribute('aria-labelledby');
473+
474+
expect(ariaLabelledby).toEqual('foobar');
475+
});
476+
});
477+
478+
describe('ariaControls', () => {
479+
it('should call onChangeComplete if value has changed since the start of interaction', () => {
480+
inputRange = renderComponent(
481+
<InputRange ariaControls="foobar" maxValue={20} minValue={0} value={values} onChange={onChange} />
482+
);
483+
484+
const slider = ReactDOM.findDOMNode(inputRange.refs.sliderMax);
485+
const handle = slider.querySelector('a');
486+
const ariaControls = handle.getAttribute('aria-controls');
487+
488+
expect(ariaControls).toEqual('foobar');
489+
});
490+
});
463491
});

0 commit comments

Comments
 (0)