Skip to content

Commit

Permalink
Add support for ariaControls and fix ariaLabelledby not working
Browse files Browse the repository at this point in the history
  • Loading branch information
esseb committed Apr 18, 2016
1 parent 1a31253 commit 38a9dc9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ If accepting a single value, pass a number to `value` prop, i.e.:
Property | Type | Description
:-----------------------|:-----------------------------------|:----------------------------------
ariaLabelledby |string |`aria-labelledby` attribute
ariaControls |string |`aria-controls` attribute
classNames |Object.<string> |CSS class names
defaultValue |number | Object.<number> |Default value(s)
disabled |boolean |Disabled or not
Expand Down
4 changes: 4 additions & 0 deletions src/InputRange/InputRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ function renderSliders(inputRange) {

const slider = (
<Slider
ariaLabelledby={ inputRange.props.ariaLabelledby }
ariaControls={ inputRange.props.ariaControls }
classNames={ classNames }
key={ key }
maxValue={ maxValue }
Expand Down Expand Up @@ -575,6 +577,7 @@ export default class InputRange extends React.Component {
* Accepted propTypes of InputRange
* @static {Object}
* @property {Function} ariaLabelledby
* @property {Function} ariaControls
* @property {Function} classNames
* @property {Function} defaultValue
* @property {Function} disabled
Expand All @@ -588,6 +591,7 @@ export default class InputRange extends React.Component {
*/
InputRange.propTypes = {
ariaLabelledby: React.PropTypes.string,
ariaControls: React.PropTypes.string,
classNames: React.PropTypes.objectOf(React.PropTypes.string),
defaultValue: maxMinValuePropType,
disabled: React.PropTypes.bool,
Expand Down
3 changes: 3 additions & 0 deletions src/InputRange/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export default class Slider extends React.Component {

<a
aria-labelledby={ this.props.ariaLabelledby }
aria-controls={ this.props.ariaControls }
aria-valuemax={ this.props.maxValue }
aria-valuemin={ this.props.minValue }
aria-valuenow={ this.props.value }
Expand All @@ -181,6 +182,7 @@ export default class Slider extends React.Component {
* Accepted propTypes of Slider
* @static {Object}
* @property {Function} ariaLabelledby
* @property {Function} ariaControls
* @property {Function} className
* @property {Function} maxValue
* @property {Function} minValue
Expand All @@ -192,6 +194,7 @@ export default class Slider extends React.Component {
*/
Slider.propTypes = {
ariaLabelledby: React.PropTypes.string,
ariaControls: React.PropTypes.string,
classNames: React.PropTypes.objectOf(React.PropTypes.string),
maxValue: React.PropTypes.number,
minValue: React.PropTypes.number,
Expand Down
28 changes: 28 additions & 0 deletions test/InputRange.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,32 @@ describe('InputRange', () => {
expect(onChangeComplete).not.toHaveBeenCalled();
});
});

describe('ariaLabelledby', () => {
it('should call onChangeComplete if value has changed since the start of interaction', () => {
inputRange = renderComponent(
<InputRange ariaLabelledby="foobar" maxValue={20} minValue={0} value={values} onChange={onChange} />
);

const slider = ReactDOM.findDOMNode(inputRange.refs.sliderMax);
const handle = slider.querySelector('a');
const ariaLabelledby = handle.getAttribute('aria-labelledby');

expect(ariaLabelledby).toEqual('foobar');
});
});

describe('ariaControls', () => {
it('should call onChangeComplete if value has changed since the start of interaction', () => {
inputRange = renderComponent(
<InputRange ariaControls="foobar" maxValue={20} minValue={0} value={values} onChange={onChange} />
);

const slider = ReactDOM.findDOMNode(inputRange.refs.sliderMax);
const handle = slider.querySelector('a');
const ariaControls = handle.getAttribute('aria-controls');

expect(ariaControls).toEqual('foobar');
});
});
});

0 comments on commit 38a9dc9

Please sign in to comment.