Skip to content
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

aria-valuetext as formatter value #646

Merged
merged 26 commits into from
Nov 22, 2016
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ Options can be passed either as a data (data-slider-foo) attribute, or as part o
| handle | string | 'round' | handle shape. Accepts: 'round', 'square', 'triangle' or 'custom' |
| reversed | bool | false | whether or not the slider should be reversed |
| enabled | bool | true | whether or not the slider is initially enabled |
| formatter | function | returns the plain value | formatter callback. Return the value wanted to be displayed in the tooltip |
| formatter | function | returns the plain value | formatter callback. Return the value wanted to be displayed in the tooltip, useful for string values. If a string is returned it will be indicated in an aria-valuetext attribute. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you wrap the "aria-valuetext" string in backticks (`) so that it stands out visually in the README?

aria-valuetext

| natural_arrow_keys | bool | false | The natural order is used for the arrow keys. Arrow up select the upper slider value for vertical sliders, arrow right the righter slider value for a horizontal slider - no matter if the slider was reversed or not. By default the arrow keys are oriented by arrow up/right to the higher slider value, arrow down/left to the lower slider value. |
| ticks | array | [ ] | Used to define the values of ticks. Tick marks are indicators to denote special values in the range. This option overwrites min and max options. |
| ticks_positions | array | [ ] | Defines the positions of the tick values in percentages. The first value should always be 0, the last value should always be 100 percent. |
Expand Down
3 changes: 3 additions & 0 deletions src/js/bootstrap-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,9 @@ const windowIsDefined = (typeof window === "object");

this.handle1.style[this.stylePos] = positionPercentages[0]+'%';
this.handle1.setAttribute('aria-valuenow', this._state.value[0]);
if (isNaN(this.options.formatter(this._state.value[0])) ) {
this.handle1.setAttribute('aria-valuetext', this.options.formatter(this._state.value[0]));
Copy link
Collaborator

@rovolution rovolution Nov 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we set this for handle2 as well?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also add a section to our README.md that documents this new ARIA property and add an example to our /tpl/index.tpl page?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about handle2...
What is it's purpose?
It always seems to be hidden and its aria-valuenow is unchanged...and defaults to 1 even when set to something else : https://fiddle.jshell.net/bbw6z63n/7/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which would be confusing to screen readers

Copy link
Collaborator

@rovolution rovolution Nov 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

about handle2...
What is it's purpose?

Purpose is the use case where we have a 2 handle slider - see Example 2 in our examples page: http://seiyria.com/bootstrap-slider/

Copy link
Collaborator

@rovolution rovolution Nov 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the README update is so that users of this library know which ARIA attributes are set on the slider

Copy link
Collaborator

@rovolution rovolution Nov 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mediaformat we are also setting aria-valuenow on this.handle2 below (line 1155), so I think it would be valuable to set it on handle2 as well

}

this.handle2.style[this.stylePos] = positionPercentages[1]+'%';
this.handle2.setAttribute('aria-valuenow', this._state.value[1]);
Expand Down
28 changes: 28 additions & 0 deletions test/specs/AriaValueTextFormatterSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
it("Sets the aria-valuetext to 'formatter' value", function() {
var textValArray = new Array('Monday','Wednesday','Friday');
var tooltipFormatter = function(value) {
var arrActiveValue = value;
return 'Current value: ' + textValArray[arrActiveValue-1];
};

//Formatter is used
var testSlider = $("#accessibilitySliderA").slider({
formatter : tooltipFormatter
});
testSlider.slider('setValue', 2);

var tooltipMessage = $("#accessibilitySliderA").siblings(".slider").children(".min-slider-handle").attr("aria-valuetext");
var expectedMessage = tooltipFormatter(2);
expect(tooltipMessage).toBe(expectedMessage);

});
it("Does not use aria-valuetext if 'formatter' is not used", function() {

//Formatter is not used
var testSliderB = $("#accessibilitySliderB").slider({});
testSliderB.slider('setValue', 2);

var ariaValueText = $("#accessibilitySliderB").siblings(".slider").children(".min-slider-handle").attr("aria-valuetext");
expect(ariaValueText).not.toBeDefined();
});