Skip to content

Commit 1f5e42e

Browse files
marcysuttongkalpak
authored andcommitted
feat(ngAria): add option to disable role=button
Closes angular#11580 Closes angular#12234
1 parent d193c3a commit 1f5e42e

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/ngAria/aria.js

Lines changed: 8 additions & 2 deletions
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

Lines changed: 12 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy