Skip to content

fix(options): add labelling options for a11y #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ The default options are:
logScale: false,
customValueToPosition: null,
customPositionToValue: null,
selectionBarGradient: null
selectionBarGradient: null,
ariaLabel: null,
ariaLabelledBy: null,
ariaLabelHigh: null,
ariaLabelledByHigh: null
}
````

Expand Down Expand Up @@ -404,6 +408,10 @@ For custom scales:

**selectionBarGradient** - _Object (default to null)_: Use to display the selection bar as a gradient. The given object must contain `from` and `to` properties which are colors.

**ariaLabel and ariaLabelHigh** - _String (default to null)_: Use to add a label directly to the slider(s) for accessibility. Adds the `aria-label` attribute.

**ariaLabelledBy and ariaLabelledByHigh** - _String (default to null)_: Use instead of ariaLabel and ariaLabelHigh to reference the id of an element which will be used to label the slider(s). Adds the `aria-labelledby` attribute.

## Change default options
If you want the change the default options for all the sliders displayed in your application, you can set them using the `RzSliderOptions.options()` method:
```js
Expand Down
4 changes: 2 additions & 2 deletions dist/rzslider.css

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions dist/rzslider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*! angularjs-slider - v6.0.2 -
(c) Rafal Zajac <[email protected]>, Valentin Hervieu <[email protected]>, Jussi Saarivirta <[email protected]>, Angelin Sirbu <[email protected]> -
https://github.com/angular-slider/angularjs-slider -
2017-03-02 */
2017-03-05 */
/*jslint unparam: true */
/*global angular: false, console: false, define, module */
(function(root, factory) {
Expand Down Expand Up @@ -81,7 +81,11 @@
logScale: false,
customValueToPosition: null,
customPositionToValue: null,
selectionBarGradient: null
selectionBarGradient: null,
ariaLabel: null,
ariaLabelledBy: null,
ariaLabelHigh: null,
ariaLabelledByHigh: null
};
var globalOptions = {};

Expand Down Expand Up @@ -893,6 +897,10 @@
this.minH.attr('tabindex', '');
if (this.options.vertical)
this.minH.attr('aria-orientation', 'vertical');
if (this.options.ariaLabel)
this.minH.attr('aria-label', this.options.ariaLabel);
else if (this.options.ariaLabelledBy)
this.minH.attr('aria-labelledby', this.options.ariaLabelledBy);

if (this.range) {
this.maxH.attr('role', 'slider');
Expand All @@ -902,6 +910,10 @@
this.maxH.attr('tabindex', '');
if (this.options.vertical)
this.maxH.attr('aria-orientation', 'vertical');
if (this.options.ariaLabelHigh)
this.maxH.attr('aria-label', this.options.ariaLabelHigh);
else if (this.options.ariaLabelledByHigh)
this.maxH.attr('aria-labelledby', this.options.ariaLabelledByHigh);
}
},

Expand Down
2 changes: 1 addition & 1 deletion dist/rzslider.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/rzslider.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/rzslider.scss

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion src/rzslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@
logScale: false,
customValueToPosition: null,
customPositionToValue: null,
selectionBarGradient: null
selectionBarGradient: null,
ariaLabel: null,
ariaLabelledBy: null,
ariaLabelHigh: null,
ariaLabelledByHigh: null
};
var globalOptions = {};

Expand Down Expand Up @@ -897,6 +901,10 @@
this.minH.attr('tabindex', '');
if (this.options.vertical)
this.minH.attr('aria-orientation', 'vertical');
if (this.options.ariaLabel)
this.minH.attr('aria-label', this.options.ariaLabel);
else if (this.options.ariaLabelledBy)
this.minH.attr('aria-labelledby', this.options.ariaLabelledBy);

if (this.range) {
this.maxH.attr('role', 'slider');
Expand All @@ -906,6 +914,10 @@
this.maxH.attr('tabindex', '');
if (this.options.vertical)
this.maxH.attr('aria-orientation', 'vertical');
if (this.options.ariaLabelHigh)
this.maxH.attr('aria-label', this.options.ariaLabelHigh);
else if (this.options.ariaLabelledByHigh)
this.maxH.attr('aria-labelledby', this.options.ariaLabelledByHigh);
}
},

Expand Down
99 changes: 99 additions & 0 deletions tests/specs/accessibility-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,105 @@
expect(helper.slider.minH.attr('aria-valuenow')).to.equal('2');
expect(helper.slider.minH.attr('aria-valuetext')).to.equal('C');
});

it('should have labelled single slider when option is set', function() {
var sliderConf = {
value: 10,
options: {
floor: 0,
ceil: 100,
step: 10,
ariaLabel: "test label"
}
};
helper.createSlider(sliderConf);
expect(helper.slider.minH.attr('aria-label')).to.equal('test label');
});

it('should have labelled range slider when option is set', function() {
var sliderConf = {
min: 10,
max: 90,
options: {
floor: 0,
ceil: 100,
step: 10,
ariaLabel: "test label",
ariaLabelHigh: "test label high"
}
};
helper.createRangeSlider(sliderConf);
expect(helper.slider.minH.attr('aria-label')).to.equal('test label');
expect(helper.slider.maxH.attr('aria-label')).to.equal('test label high');
});

it('should have labelled by id on single slider when option is set', function() {
var sliderConf = {
value: 10,
options: {
floor: 0,
ceil: 100,
step: 10,
ariaLabelledBy: "testId"
}
};
helper.createSlider(sliderConf);
expect(helper.slider.minH.attr('aria-labelledby')).to.equal('testId');
});

it('should have labelled by id on range slider when option is set', function() {
var sliderConf = {
min: 10,
max: 90,
options: {
floor: 0,
ceil: 100,
step: 10,
ariaLabelledBy: "testId",
ariaLabelledByHigh: "testIdHigh"
}
};
helper.createRangeSlider(sliderConf);
expect(helper.slider.minH.attr('aria-labelledby')).to.equal('testId');
expect(helper.slider.maxH.attr('aria-labelledby')).to.equal('testIdHigh');
});

it('should not have labelled by id on single slider when both options set', function() {
var sliderConf = {
value: 10,
options: {
floor: 0,
ceil: 100,
step: 10,
ariaLabel: "test label",
ariaLabelledBy: "testId"
}
};
helper.createSlider(sliderConf);
expect(helper.slider.minH.attr('aria-label')).to.equal('test label');
expect(helper.slider.minH.attr('aria-labelledby')).to.equal(undefined);
});

it('should not have labelled by id on range slider when both options set', function() {
var sliderConf = {
min: 10,
max: 90,
options: {
floor: 0,
ceil: 100,
step: 10,
ariaLabel: "test label",
ariaLabelHigh: "test label high",
ariaLabelledBy: "testId",
ariaLabelledByHigh: "testIdHigh"
}
};
helper.createRangeSlider(sliderConf);
expect(helper.slider.minH.attr('aria-label')).to.equal('test label');
expect(helper.slider.maxH.attr('aria-label')).to.equal('test label high');
expect(helper.slider.minH.attr('aria-labelledby')).to.equal(undefined);
expect(helper.slider.maxH.attr('aria-labelledby')).to.equal(undefined);
});
});
}());