Skip to content

Commit 91776c2

Browse files
author
Marcy Sutton
committed
feat(ngAria): Adds button role to ng-click
Closes angular#9254
1 parent 84a9dc9 commit 91776c2

File tree

2 files changed

+100
-73
lines changed

2 files changed

+100
-73
lines changed

src/ngAria/aria.js

+21-9
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
*
2121
* Below is a more detailed breakdown of the attributes handled by ngAria:
2222
*
23-
* | Directive | Supported Attributes |
24-
* |---------------------------------------------|----------------------------------------------------------------------------------------|
25-
* | {@link ng.directive:ngModel ngModel} | aria-checked, aria-valuemin, aria-valuemax, aria-valuenow, aria-invalid, aria-required |
26-
* | {@link ng.directive:ngDisabled ngDisabled} | aria-disabled |
27-
* | {@link ng.directive:ngShow ngShow} | aria-hidden |
28-
* | {@link ng.directive:ngHide ngHide} | aria-hidden |
29-
* | {@link ng.directive:ngClick ngClick} | tabindex, keypress event |
30-
* | {@link ng.directive:ngDblclick ngDblclick} | tabindex |
31-
* | {@link module:ngMessages ngMessages} | aria-live |
23+
* | Directive | Supported Attributes |
24+
* |---------------------------------------------|-----------------------------------------------------------------------------------------------------|
25+
* | {@link ng.directive:ngModel ngModel} | aria-checked, aria-valuemin, aria-valuemax, aria-valuenow, aria-invalid, aria-required, input roles |
26+
* | {@link ng.directive:ngDisabled ngDisabled} | aria-disabled |
27+
* | {@link ng.directive:ngShow ngShow} | aria-hidden |
28+
* | {@link ng.directive:ngHide ngHide} | aria-hidden |
29+
* | {@link ng.directive:ngClick ngClick} | tabindex, keypress event, button role |
30+
* | {@link ng.directive:ngDblclick ngDblclick} | tabindex |
31+
* | {@link module:ngMessages ngMessages} | aria-live |
3232
*
3333
* Find out more information about each directive by reading the
3434
* {@link guide/accessibility ngAria Developer Guide}.
@@ -329,6 +329,18 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
329329
}
330330
});
331331
}
332+
333+
function isNodeOneOf(elem, nodeTypeArray) {
334+
for (var i=0; i < nodeTypeArray.length; i++) {
335+
if (elem[0].nodeName === nodeTypeArray[i]) {
336+
return true;
337+
}
338+
}
339+
}
340+
341+
if (!elem.attr('role') && !isNodeOneOf(elem, ['BUTTON', 'A'])) {
342+
elem.attr('role', 'button');
343+
}
332344
}
333345
};
334346
}])

0 commit comments

Comments
 (0)