Skip to content

Commit cb6e000

Browse files
author
Marcy Sutton
committed
feat(ngAria): Adds button role to ng-click
Closes angular#9254
1 parent 93253df commit cb6e000

File tree

2 files changed

+97
-69
lines changed

2 files changed

+97
-69
lines changed

src/ngAria/aria.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
*
2323
* | Directive | Supported Attributes |
2424
* |---------------------------------------------|----------------------------------------------------------------------------------------|
25-
* | {@link ng.directive:ngModel ngModel} | aria-checked, aria-valuemin, aria-valuemax, aria-valuenow, aria-invalid, aria-required |
2625
* | {@link ng.directive:ngDisabled ngDisabled} | aria-disabled |
2726
* | {@link ng.directive:ngShow ngShow} | aria-hidden |
2827
* | {@link ng.directive:ngHide ngHide} | aria-hidden |
29-
* | {@link ng.directive:ngClick ngClick} | tabindex, keypress event |
3028
* | {@link ng.directive:ngDblclick ngDblclick} | tabindex |
3129
* | {@link module:ngMessages ngMessages} | aria-live |
30+
* | {@link ng.directive:ngModel ngModel} | aria-checked, aria-valuemin, aria-valuemax, aria-valuenow, aria-invalid, aria-required, input roles |
31+
* | {@link ng.directive:ngClick ngClick} | tabindex, keypress event, button role |
3232
*
3333
* Find out more information about each directive by reading the
3434
* {@link guide/accessibility ngAria Developer Guide}.
@@ -320,6 +320,9 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
320320
return true;
321321
}
322322
}
323+
if (!elem.attr('role') && !isNodeOneOf(elem, ['BUTTON', 'A'])) {
324+
elem.attr('role', 'button');
325+
}
323326

324327
if ($aria.config('tabindex') && !elem.attr('tabindex')) {
325328
elem.attr('tabindex', 0);
@@ -337,6 +340,16 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
337340
});
338341
}
339342
};
343+
344+
function isNodeOneOf(elem, nodeTypeArray) {
345+
for (var i=0; i < nodeTypeArray.length; i++) {
346+
if (elem[0].nodeName === nodeTypeArray[i]) {
347+
return true;
348+
}
349+
}
350+
}
351+
352+
340353
}
341354
};
342355
}])

0 commit comments

Comments
 (0)