Skip to content

Commit 8c148b8

Browse files
marcysuttonnetman92
authored andcommitted
feat(ngAria): add option to disable role=button
Closes angular#11580 Closes angular#12234
1 parent aad2269 commit 8c148b8

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/ngAria/aria.js

+8-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+
bindRoleForClick: true
8788
};
8889

8990
/**
@@ -102,6 +103,8 @@ 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+
* - **bindRoleForClick** – `{boolean}` – Adds role=button to non-interactive elements like `div`
107+
* using ng-click, making them more accessible to users of assistive technologies
105108
*
106109
* @description
107110
* Enables/disables various ARIA attributes
@@ -346,7 +349,10 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
346349
return true;
347350
}
348351
}
349-
if (!elem.attr('role') && !isNodeOneOf(elem, nodeBlackList)) {
352+
353+
if ($aria.config('bindRoleForClick')
354+
&& !elem.attr('role')
355+
&& !isNodeOneOf(elem, nodeBlackList)) {
350356
elem.attr('role', 'button');
351357
}
352358

test/ngAria/ariaSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,18 @@ describe('$aria', function() {
750750
});
751751
});
752752

753+
describe('actions when bindRoleForClick is set to false', function() {
754+
beforeEach(configAriaProvider({
755+
bindRoleForClick: false
756+
}));
757+
beforeEach(injectScopeAndCompiler);
758+
759+
it('should not add a button role', function() {
760+
compileElement('<radio-group ng-click="something"></radio-group>');
761+
expect(element.attr('role')).toBeUndefined();
762+
});
763+
});
764+
753765
describe('actions when bindKeypress is set to false', function() {
754766
beforeEach(configAriaProvider({
755767
bindKeypress: false

0 commit comments

Comments
 (0)