Skip to content

Commit 427ace2

Browse files
author
Valentin Hervieu
committed
Add aria role and aria-value attributes
1 parent f6acc64 commit 427ace2

File tree

4 files changed

+105
-34
lines changed

4 files changed

+105
-34
lines changed

dist/rzslider.js

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@
309309
self.updateLowHandle(self.valueToOffset(self.scope.rzSliderModel));
310310
self.updateSelectionBar();
311311
self.updateTicksScale();
312+
self.updateAriaAttributes();
312313

313314
if (self.range) {
314315
self.updateCmbLabel();
@@ -322,6 +323,7 @@
322323
self.updateSelectionBar();
323324
self.updateTicksScale();
324325
self.updateCmbLabel();
326+
self.updateAriaAttributes();
325327
}, self.options.interval);
326328

327329
this.scope.$on('rzSliderForceRender', function() {
@@ -614,14 +616,43 @@
614616
},
615617

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

627658
/**
@@ -1111,9 +1142,11 @@
11111142
this.ticks.on('touchstart', angular.bind(this, this.onStart, null, null));
11121143
this.ticks.on('touchstart', angular.bind(this, this.onMove, this.ticks));
11131144

1114-
this.minH.on('focus', angular.bind(this, this.onPointerFocus, this.minH, 'rzSliderModel'))
1115-
if (this.range) {
1116-
this.maxH.on('focus', angular.bind(this, this.onPointerFocus, this.maxH, 'rzSliderHigh'));
1145+
if (this.options.keyboardSupport) {
1146+
this.minH.on('focus', angular.bind(this, this.onPointerFocus, this.minH, 'rzSliderModel'))
1147+
if (this.range) {
1148+
this.maxH.on('focus', angular.bind(this, this.onPointerFocus, this.maxH, 'rzSliderHigh'));
1149+
}
11171150
}
11181151
},
11191152

@@ -1157,7 +1190,9 @@
11571190
}
11581191

11591192
pointer.addClass('rz-active');
1160-
pointer[0].focus();
1193+
1194+
if (this.options.keyboardSupport)
1195+
pointer[0].focus();
11611196

11621197
ehMove = angular.bind(this, this.dragging.active ? this.onDragMove : this.onMove, pointer);
11631198
ehEnd = angular.bind(this, this.onEnd, ehMove);
@@ -1206,29 +1241,26 @@
12061241
onEnd: function(ehMove, event) {
12071242
var moveEventName = this.getEventNames(event).moveEvent;
12081243

1209-
//this.minH.removeClass('rz-active');
1210-
//this.maxH.removeClass('rz-active');
1244+
if (!this.options.keyboardSupport) {
1245+
this.minH.removeClass('rz-active');
1246+
this.maxH.removeClass('rz-active');
1247+
this.tracking = '';
1248+
}
1249+
this.dragging.active = false;
12111250

12121251
$document.off(moveEventName, ehMove);
1213-
12141252
this.scope.$emit('slideEnded');
1215-
//this.tracking = '';
1216-
1217-
this.dragging.active = false;
12181253
this.callOnEnd();
12191254
},
12201255

12211256
onPointerFocus: function(pointer, ref, event) {
1222-
//if (this.tracking === ref) return;
12231257
this.tracking = ref;
1224-
console.info('focused', ref);
12251258
pointer.one('blur', angular.bind(this, this.onPointerBlur, pointer));
12261259
pointer.on('keydown', angular.bind(this, this.onKeyboardEvent));
12271260
pointer.addClass('rz-active');
12281261
},
12291262

12301263
onPointerBlur: function(pointer, event) {
1231-
console.info('blured', this.tracking);
12321264
pointer.off('keydown');
12331265
this.tracking = '';
12341266
pointer.removeClass('rz-active');
@@ -1370,6 +1402,7 @@
13701402
switched = true;
13711403
this.scope[this.tracking] = this.scope.rzSliderHigh;
13721404
this.updateHandles(this.tracking, this.maxH.rzsp);
1405+
this.updateAriaAttributes();
13731406
this.tracking = 'rzSliderHigh';
13741407
this.minH.removeClass('rz-active');
13751408
this.maxH.addClass('rz-active');
@@ -1380,6 +1413,7 @@
13801413
switched = true;
13811414
this.scope[this.tracking] = this.scope.rzSliderModel;
13821415
this.updateHandles(this.tracking, this.minH.rzsp);
1416+
this.updateAriaAttributes();
13831417
this.tracking = 'rzSliderModel';
13841418
this.maxH.removeClass('rz-active');
13851419
this.minH.addClass('rz-active');
@@ -1392,6 +1426,7 @@
13921426
if (this.scope[this.tracking] !== newValue) {
13931427
this.scope[this.tracking] = newValue;
13941428
this.updateHandles(this.tracking, newOffset);
1429+
this.updateAriaAttributes();
13951430
this.scope.$apply();
13961431
this.callOnChange();
13971432
}
@@ -1493,7 +1528,7 @@
14931528
'use strict';
14941529

14951530
$templateCache.put('rzSliderTpl.html',
1496-
"<span class=rz-bar-wrapper><span class=rz-bar></span></span> <span class=rz-bar-wrapper><span class=\"rz-bar rz-selection\"></span></span> <span class=rz-pointer tabindex=0></span> <span class=rz-pointer tabindex=0></span> <span class=\"rz-bubble rz-limit\"></span> <span class=\"rz-bubble rz-limit\"></span> <span class=rz-bubble></span> <span class=rz-bubble></span> <span class=rz-bubble></span><ul class=rz-ticks></ul>"
1531+
"<span class=rz-bar-wrapper><span class=rz-bar></span></span> <span class=rz-bar-wrapper><span class=\"rz-bar rz-selection\"></span></span> <span class=rz-pointer></span> <span class=rz-pointer></span> <span class=\"rz-bubble rz-limit\"></span> <span class=\"rz-bubble rz-limit\"></span> <span class=rz-bubble></span> <span class=rz-bubble></span> <span class=rz-bubble></span><ul class=rz-ticks></ul>"
14971532
);
14981533

14991534
}]);

0 commit comments

Comments
 (0)