Skip to content

Commit 7a3b398

Browse files
author
Valentin Hervieu
committed
Add aria role and aria-value attributes
1 parent c812f4d commit 7a3b398

File tree

3 files changed

+103
-31
lines changed

3 files changed

+103
-31
lines changed

dist/rzslider.js

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
ticksValuesTooltip: null,
5252
vertical: false,
5353
selectionBarColor: null,
54+
keyboardSupport: true,
5455
scale: 1,
5556
onStart: null,
5657
onChange: null,
@@ -310,6 +311,7 @@
310311
self.updateLowHandle(self.valueToOffset(self.scope.rzSliderModel));
311312
self.updateSelectionBar();
312313
self.updateTicksScale();
314+
self.updateAriaAttributes();
313315

314316
if (self.range) {
315317
self.updateCmbLabel();
@@ -323,6 +325,7 @@
323325
self.updateSelectionBar();
324326
self.updateTicksScale();
325327
self.updateCmbLabel();
328+
self.updateAriaAttributes();
326329
}, self.options.interval);
327330

328331
this.scope.$on('rzSliderForceRender', function() {
@@ -614,14 +617,43 @@
614617
},
615618

616619
/**
617-
* Adds accessibility atributes
620+
* Adds accessibility attributes
618621
*
619622
* Run only once during initialization
620623
*
621624
* @returns {undefined}
622625
*/
623626
addAccessibility: function() {
624-
this.sliderElem.attr("role", "slider");
627+
this.minH.attr('role', 'slider');
628+
this.updateAriaAttributes();
629+
if (this.options.keyboardSupport)
630+
this.minH.attr('tabindex', '0');
631+
if (this.options.vertical)
632+
this.minH.attr('aria-orientation', 'vertical');
633+
634+
if (this.range) {
635+
this.maxH.attr('role', 'slider');
636+
if (this.options.keyboardSupport)
637+
this.maxH.attr('tabindex', '0');
638+
if (this.options.vertical)
639+
this.maxH.attr('aria-orientation', 'vertical');
640+
}
641+
},
642+
643+
/**
644+
* Updates aria attributes according to current values
645+
*/
646+
updateAriaAttributes: function() {
647+
this.minH.attr('aria-valuenow', this.scope.rzSliderModel);
648+
this.minH.attr('aria-valuetext', this.customTrFn(this.scope.rzSliderModel));
649+
this.minH.attr('aria-valuemin', this.minValue);
650+
this.minH.attr('aria-valuemax', this.maxValue);
651+
if (this.range) {
652+
this.maxH.attr('aria-valuenow', this.scope.rzSliderHigh);
653+
this.maxH.attr('aria-valuetext', this.customTrFn(this.scope.rzSliderHigh));
654+
this.maxH.attr('aria-valuemin', this.minValue);
655+
this.maxH.attr('aria-valuemax', this.maxValue);
656+
}
625657
},
626658

627659
/**
@@ -1126,9 +1158,11 @@
11261158
this.ticks.on('touchstart', angular.bind(this, this.onStart, null, null));
11271159
this.ticks.on('touchstart', angular.bind(this, this.onMove, this.ticks));
11281160

1129-
this.minH.on('focus', angular.bind(this, this.onPointerFocus, this.minH, 'rzSliderModel'))
1130-
if (this.range) {
1131-
this.maxH.on('focus', angular.bind(this, this.onPointerFocus, this.maxH, 'rzSliderHigh'));
1161+
if (this.options.keyboardSupport) {
1162+
this.minH.on('focus', angular.bind(this, this.onPointerFocus, this.minH, 'rzSliderModel'))
1163+
if (this.range) {
1164+
this.maxH.on('focus', angular.bind(this, this.onPointerFocus, this.maxH, 'rzSliderHigh'));
1165+
}
11321166
}
11331167
},
11341168

@@ -1172,7 +1206,9 @@
11721206
}
11731207

11741208
pointer.addClass('rz-active');
1175-
pointer[0].focus();
1209+
1210+
if (this.options.keyboardSupport)
1211+
pointer[0].focus();
11761212

11771213
ehMove = angular.bind(this, this.dragging.active ? this.onDragMove : this.onMove, pointer);
11781214
ehEnd = angular.bind(this, this.onEnd, ehMove);
@@ -1221,29 +1257,26 @@
12211257
onEnd: function(ehMove, event) {
12221258
var moveEventName = this.getEventNames(event).moveEvent;
12231259

1224-
//this.minH.removeClass('rz-active');
1225-
//this.maxH.removeClass('rz-active');
1260+
if (!this.options.keyboardSupport) {
1261+
this.minH.removeClass('rz-active');
1262+
this.maxH.removeClass('rz-active');
1263+
this.tracking = '';
1264+
}
1265+
this.dragging.active = false;
12261266

12271267
$document.off(moveEventName, ehMove);
1228-
12291268
this.scope.$emit('slideEnded');
1230-
//this.tracking = '';
1231-
1232-
this.dragging.active = false;
12331269
this.callOnEnd();
12341270
},
12351271

12361272
onPointerFocus: function(pointer, ref, event) {
1237-
//if (this.tracking === ref) return;
12381273
this.tracking = ref;
1239-
console.info('focused', ref);
12401274
pointer.one('blur', angular.bind(this, this.onPointerBlur, pointer));
12411275
pointer.on('keydown', angular.bind(this, this.onKeyboardEvent));
12421276
pointer.addClass('rz-active');
12431277
},
12441278

12451279
onPointerBlur: function(pointer, event) {
1246-
console.info('blured', this.tracking);
12471280
pointer.off('keydown');
12481281
this.tracking = '';
12491282
pointer.removeClass('rz-active');
@@ -1386,6 +1419,7 @@
13861419
switched = true;
13871420
this.scope[this.tracking] = this.scope.rzSliderHigh;
13881421
this.updateHandles(this.tracking, this.maxH.rzsp);
1422+
this.updateAriaAttributes();
13891423
this.tracking = 'rzSliderHigh';
13901424
this.minH.removeClass('rz-active');
13911425
this.maxH.addClass('rz-active');
@@ -1394,6 +1428,7 @@
13941428
switched = true;
13951429
this.scope[this.tracking] = this.scope.rzSliderModel;
13961430
this.updateHandles(this.tracking, this.minH.rzsp);
1431+
this.updateAriaAttributes();
13971432
this.tracking = 'rzSliderModel';
13981433
this.maxH.removeClass('rz-active');
13991434
this.minH.addClass('rz-active');
@@ -1404,6 +1439,7 @@
14041439
if (this.scope[this.tracking] !== newValue) {
14051440
this.scope[this.tracking] = newValue;
14061441
this.updateHandles(this.tracking, newOffset);
1442+
this.updateAriaAttributes();
14071443
valueChanged = true;
14081444
}
14091445

0 commit comments

Comments
 (0)