Roles dynamically added with ngAria #10318
Conversation
CLAs look good, thanks! |
I know it is unrelated to this PR, but I was wondering (with regard to line 209):
What if the element has both a type and a role (and they are different) ? |
@gkalpak not for checkbox. |
@marcysutton: Aha, thx. So, if I interpret your answer correctly, in the "general" case each attribute (type, role) should be checked separately:
But for checkboxes and radios,
(which will essentially ignore Is my thinking correct ? |
compileInput('<div ng-click="someFunction()"></div>'); | ||
expect(element.attr('role')).toBe('button'); | ||
}); | ||
it('should not add role="button" to anchor', function() { |
caitp
Dec 5, 2014
Contributor
nit: 2 empty lines between each suite/spec/block
nit: 2 empty lines between each suite/spec/block
beforeEach(injectScopeAndCompiler); | ||
|
||
it('should add missing role="button" to custom input', function() { | ||
compileInput('<div ng-click="someFunction()"></div>'); |
caitp
Dec 5, 2014
Contributor
why are we calling this compileInput
? there's no input here =)
why are we calling this compileInput
? there's no input here =)
marcysutton
Dec 5, 2014
Author
Contributor
Good point! This is fixed.
Good point! This is fixed.
@@ -319,6 +329,10 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) { | |||
} | |||
}); | |||
} | |||
|
|||
if (!elem.attr('role') && (elem[0].nodeName !== 'BUTTON') && (elem[0].nodeName !== 'A')) { |
caitp
Dec 5, 2014
Contributor
I wonder if it would be more readable to have something like && !IsNodeOneOf(elem, "BUTTON", "A")
or something. I don't think it's problematic like this, but if there was one extra condition added it would be really hard to read.
I wonder if it would be more readable to have something like && !IsNodeOneOf(elem, "BUTTON", "A")
or something. I don't think it's problematic like this, but if there was one extra condition added it would be really hard to read.
marcysutton
Dec 5, 2014
Author
Contributor
Great point. That conditional is a little awkward in its current form.
Great point. That conditional is a little awkward in its current form.
@gkalpak there is no "generic" case. ngAria is checking for specific scenarios to add the right attributes. |
OK, thx ! I get it (I think :)) |
cb6e000
to
0cdd758
@@ -310,6 +320,9 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) { | |||
return true; | |||
} | |||
} | |||
if (!elem.attr('role') && !isNodeOneOf(elem, ['BUTTON', 'A'])) { |
dylanb
Feb 7, 2015
blacklist should include INPUT and TEXTAREA
blacklist should include INPUT and TEXTAREA
marcysutton
Feb 7, 2015
Author
Contributor
Good call. But do people put ng-click
on those? shudder
Good call. But do people put ng-click
on those? shudder
dylanb
Feb 7, 2015
input type=image, type=submit, type=button will all commonly have ng-click attributes applied
input type=image, type=submit, type=button will all commonly have ng-click attributes applied
marcysutton
Feb 7, 2015
Author
Contributor
Great point. I updated the blacklist and added it to the dynamic keypress binding so there would be more consistency.
Great point. I updated the blacklist and added it to the dynamic keypress binding so there would be more consistency.
@caitp I rebased this branch with the recently merged ngAria changes. The code now uses a node blacklist to add roles and bind keypress events. |
@Narretz @petebacondarwin can you take a look at this PR for adding roles dynamically? It's the last ngAria change that would be great to have in the 1.4 release. Thank you! |
}); | ||
|
||
it('should add missing role="checkbox" to custom input', function() { | ||
scope.$apply('val = true'); |
gkalpak
Feb 16, 2015
Member
What is the purpose of this line ?
What is the purpose of this line ?
marcysutton
Feb 17, 2015
Author
Contributor
It was unnecessary. Cleaned up!
It was unnecessary. Cleaned up!
Adds missing roles: slider, radio, checkbox Closes #10012
LGTM |
Would love to see this in 1.3.x. We have some tags that are clickable and are currently having to do some extra work with ng-keypress to make them fully accessible. Having a blacklist rather than the current div & li whitelist would be extremely useful. |
|
Landed in master and cherry picked to 1.3.x for good measure. |
Woohoo! Thanks @petebacondarwin! |
This change adds the missing roles: `slider`, `radio`, `checkbox` Closes angular#10012 Closes angular#10318
This change adds the missing roles: `slider`, `radio`, `checkbox` Closes angular#10012 Closes angular#10318
To communicate the purpose of custom inputs with a type of
range
,checkbox
orradio
, ngAria now dynamically adds roles to custom radio buttons, checkboxes and sliders.It also adds a role of
button
to any element withngClick
that is not abutton
,anchor
,input
ortextarea
(such as adiv
). This feature comes on the heels of #10288, which binds thekeypress
event forngClick
. With these two changes together, users of assistive technologies will know what they are focused on and be able to operate controls with the keyboard (this is important becausengAria
dynamically addstabIndex="0"
withngClick
). However, not all uses of ngClick are used for buttons–sometimes developers bindng-click
on the document. In this scenario, a role can be overridden by the developer ifbutton
does not match expected behavior.Note: This change does not implement any kind of flag allowing the user to opt out of roles being set.
Closes #9254 and #10012.