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

Make sliderInput() accessible for keyboard and screen readers #3011

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions inst/www/shared/ionrangeslider/js/ion.rangeSlider.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@
*/
pointerDown: function (target, e) {
e.preventDefault();
e.stopPropagation();
if (e.stopPropagation) e.stopPropagation();
var x = e.pageX || e.originalEvent.touches && e.originalEvent.touches[0].pageX;
if (e.button === 2) {
return;
Expand Down Expand Up @@ -860,7 +860,7 @@
*/
pointerClick: function (target, e) {
e.preventDefault();
e.stopPropagation();
if (e.stopPropagation) e.stopPropagation();
var x = e.pageX || e.originalEvent.touches && e.originalEvent.touches[0].pageX;
if (e.button === 2) {
return;
Expand Down
2 changes: 1 addition & 1 deletion inst/www/shared/ionrangeslider/js/ion.rangeSlider.min.js

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions inst/www/shared/shiny.js

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

2 changes: 1 addition & 1 deletion inst/www/shared/shiny.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/www/shared/shiny.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/www/shared/shiny.min.js.map

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions srcjs/input_binding_slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,37 @@ $.extend(sliderInputBinding, textInputBinding, {

opts.prettify = getTypePrettifyer(dataType, timeFormat, timezone);

function setAriaLabels(el, label, value, min, max) {
if (!el.length) return;
el.attr({
"role": "slider", "tabindex": "0",
"aria-labelledby": label,
"aria-valuenow": value,
"aria-valuemin": min,
"aria-valuemax": max
});
};

// Ensure accessibility labels are updated when the slider updates (programmatically or interactively)
function updateAriaLabels(data) {
var isSingleValue = !data.input.data("to");
var line = data.slider.find(".irs-line");
var label = el.id + "-label";
if (isSingleValue) {
setAriaLabels(line, label, data.from, data.min, data.max);
return;
}
line.attr("tabindex", "-1");
var from = data.slider.find(".irs-from");
setAriaLabels(from, label + "-lower", data.from, data.min, data.max);

Choose a reason for hiding this comment

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

el.id + "-label" is tied to ./R/input-utils.R#L7, and is calling a label string defined within shinyInputLabel().

This is not a right way to concatenate label string. Please take a look at this document.

Choose a reason for hiding this comment

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

We could make an invisible <span id = "lower"> with the inner text as "lower", and then pass this span id to the aria-labelledby right after the original label id using a whitespace separator to concatenate. I know, it is sort of tricky... I'm sorry.

Choose a reason for hiding this comment

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

el.id + "-label" is tied to ./R/input-utils.R#L7, and is calling a label string defined within shinyInputLabel().

This is not a right way to concatenate label string. Please take a look at this document.

var to = data.slider.find(".irs-to");
setAriaLabels(to, label + "-upper", data.to, data.min, data.max);

Choose a reason for hiding this comment

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

The same issue as the above.

};

opts.onStart = updateAriaLabels;
opts.onChange = updateAriaLabels;
opts.onUpdate = updateAriaLabels;

$el.ionRangeSlider(opts);
},
_getLabelNode: function(el) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ index 2fe2c8d..89d204e 100644
*/
pointerDown: function (target, e) {
e.preventDefault();
+ e.stopPropagation();
+ if (e.stopPropagation) e.stopPropagation();
var x = e.pageX || e.originalEvent.touches && e.originalEvent.touches[0].pageX;
if (e.button === 2) {
return;
@@ -859,6 +860,7 @@
*/
pointerClick: function (target, e) {
e.preventDefault();
+ e.stopPropagation();
+ if (e.stopPropagation) e.stopPropagation();
var x = e.pageX || e.originalEvent.touches && e.originalEvent.touches[0].pageX;
if (e.button === 2) {
return;