Skip to content

Commit e728efc

Browse files
committed
fix(ngAria): add config option for role=button
Closes angular#11580
1 parent a777616 commit e728efc

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Diff for: src/ngAria/aria.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ function $AriaProvider() {
8383
ariaMultiline: true,
8484
ariaValue: true,
8585
tabindex: true,
86-
bindKeypress: true
86+
bindKeypress: true,
87+
clickRole: true
8788
};
8889

8990
/**
@@ -102,6 +103,7 @@ function $AriaProvider() {
102103
* - **tabindex** – `{boolean}` – Enables/disables tabindex tags
103104
* - **bindKeypress** – `{boolean}` – Enables/disables keypress event binding on `<div>` and
104105
* `<li>` elements with ng-click
106+
* - **clickRole** – `{boolean}` – Adds role=button to non-interactive elements with ng-click
105107
*
106108
* @description
107109
* Enables/disables various ARIA attributes
@@ -348,7 +350,7 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
348350

349351
if (!$aria.isNodeOneOf(elem, $aria.nodeBlackList)) {
350352

351-
if (!elem.attr('role')) {
353+
if ($aria.config('clickRole') && !elem.attr('role')) {
352354
elem.attr('role', 'button');
353355
}
354356

Diff for: test/ngAria/ariaSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,18 @@ describe('$aria', function() {
256256
});
257257
});
258258

259+
describe('custom ng-clicks', function() {
260+
beforeEach(configAriaProvider({
261+
clickRole: false
262+
}));
263+
beforeEach(injectScopeAndCompiler);
264+
265+
it('should not add a role', function() {
266+
compileElement('<radio-group ng-click="something"></radio-group>');
267+
expect(element.attr('role')).toBeUndefined();
268+
})
269+
})
270+
259271
describe('aria-checked when disabled', function() {
260272
beforeEach(configAriaProvider({
261273
ariaChecked: false

0 commit comments

Comments
 (0)