-
Notifications
You must be signed in to change notification settings - Fork 27.5k
bug(ngAria): native controls fire a single click event #10766
Conversation
3f251ba
to
ec66e16
Compare
@@ -83,7 +83,8 @@ function $AriaProvider() { | |||
ariaMultiline: true, | |||
ariaValue: true, | |||
tabindex: true, | |||
bindKeypress: true | |||
bindKeypress: true, | |||
keypressEls: ['DIV', 'LI'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather trivial and probably a matter of personal style, but I would prefer a non- abbreviated name (keypressElements
, keypressNodeNames
etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like keypressNodeNames
. I've changed it to that. Thanks for the suggestion!
ec66e16
to
35504fa
Compare
@caitp this is ready for another review. |
@@ -526,6 +538,31 @@ describe('$aria', function() { | |||
element.triggerHandler({ type: 'keypress', keyCode: 13 }); | |||
expect(element.text()).toBe('keypress13'); | |||
}); | |||
|
|||
it('should not bind keypress to non-div elements', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be good to note in the spec title that this is a symptom of using the default config. (This might be spelled out clearly higher up, can't tell on mobile view)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. I've updated it.
Still LGTM |
35504fa
to
93dd331
Compare
@@ -83,7 +83,8 @@ function $AriaProvider() { | |||
ariaMultiline: true, | |||
ariaValue: true, | |||
tabindex: true, | |||
bindKeypress: true | |||
bindKeypress: true, | |||
keypressNodeNames: ['DIV', 'LI'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still kind of feel like this is a really weird API. Chances are, you're going to want emulated clicks for any element that doesn't produce them on their own, right? if this array gets out there and people start using it, we won't be able to get rid of it later. Lets make sure this is needed before doing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point. <button>
is the biggest issue we had, since it gets both click and keypress. <a>
should not be used with ng-click
(that's what buttons are for) but rather ng-href
and routing...although I suppose that could be abused. There's also the <details>
/<summary>
elements, <dialog>
, form controls, and a few more. An interesting thing to consider, as well, is the work being done on Custom Elements and tabindex: https://docs.google.com/document/d/1k93Ez6yNSyWQDtGjdJJqTBPmljk9l2WS3JTe5OHHB50/edit#heading=h.tf9twftfr65h
So, we need some mechanism of checking whether or not to apply keypress–I'm personally in favor of opt-in for <div>
and <li>
so that it limits the scope of this behavior. It's just a question of whether we want that list to be configurable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configurable is good, but I think we shouldn't expose an array for it at least.
If we decide we don't want it to be configurable and just "do the right thing always" later, it's trivial to replace configuration methods with noop
, and not have anything unnecessary taking up space in the framework. So I see that as being preferable, tbh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like
// enable keypress on all elements!
$ariaProvider.keypressClickElements('*');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that allow all elements by default? How would we discern between <div>
and <button>
(and fix the issue this is trying to address) out of the box?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@caitp revisiting this so we can get a fix in to the next release. I'm still unclear how we would fix the bug with a wildcard for all elements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wildcard case would just not filter, or only blacklist known-issue elements, I guess.
Maybe it's not worth worrying about it and just land it, @lgalfaso what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we just do away with the config for elements and limit dynamic binding of keypress to div
and li
? We could wait and see if anyone actually needs it to be configurable. You'd still be able to disable it with the bindKeypress
flag.
0e4f397
to
eea9805
Compare
eea9805
to
5dcb824
Compare
@caitp I simplified the code to just Do the Right Thing™ without a configuration array. I also updated the docs. |
okay, i think a blacklist would be better than a whitelist, but this is fine for now... @petebacondarwin / @Narretz / @lgalfaso could you merge this before monday? |
Will do |
Thanks @petebacondarwin! |
try this .. its 100% works for me ... .config(function( $mdGestureProvider ) { source.. |
@Ashutosh7376 that is unrelated to this change, and only applicable to Angular Material. |
To fix the widespread accessibility issue of
ngClick
on divs, ngAria dynamically bindskeypress
in addition totabIndex
. As first implemented, this introduced a bug where<button>
elements would have both events bound, causing multiple callbacks to fire. This PR makes limits the addition of keypress to<div>
and<li>
, which can be overridden with thebindKeypress
config option.Closes #10388. Thanks to @caitp for the help & unit test on native elements.