-
Notifications
You must be signed in to change notification settings - Fork 27.4k
bug(ngAria): ng-click adds keypress event to buttons which already fire a click event on "enter" #10388
Comments
There is more work to do before I can submit a PR for this bug, but I want to post what I have so far to hopefully get more eyes on it. In a failing unit test, |
An alternative approach would be to try and keep the callback from firing more than once, rather than excluding |
@marcysutton from a glance, it looks like the spy API is being used incorrectly and not calling your original function --- I don't think jasmine will use the "andCallThrough" behaviour by default. Try changing it to |
Hi @caitp! I've updated it, but it still doesn't fire the callback even with the |
@marcysutton look at my blog post here for how screen readers act when you add ARIA roles to things http://unobfuscated.blogspot.com/2013/05/event-handlers-and-screen-readers.html |
@marcysutton wait --- So the code is saying "if we are binding keypresses, there's no keypress handler, AND we aren't a button/anchor tag, then add the event listener" --- and your test is creating a button tag and asserting that the keypress handler is used. If you're wanting to test that the browser itself is sending the right event, that's harder --- we might need to write an E2E test for that, but I would see if |
@caitp yes, but the test is just asserting that the ngClick handler is executed when triggered by |
Yes, the browser will send a click event after getting the keypress event, but you won't be able to test that with |
So I still haven't figured out how to test this in unit or end-to-end tests, but I was able to repro the original bug and see it fixed in a live demo: http://codepen.io/marcysutton/pen/ogYNPM The fix proposed is to only bind the additional keypress event if the element is not a If we're okay with this change going in without tests repro'ing the bug, I can submit a PR. |
there might be other elements that need to be considered, I'm not sure. I'll look at writing a test for this after le meeting |
Thanks for your work @marcysutton. I'll look forward to upgrading when this fix is released! :D |
We could also do it as an opt-in instead of an opt-out, and give people a config. Start with That said, anything that becomes interactive needs to be communicated as such. An open PR for roles, which I need to revisit: #10012 |
@caitp any update on that test? I've updated my code to be opt-in, so it only applies the keypress to DIV elements. https://github.com/marcysutton/angular.js/compare/ngaria-ngclick-bugfix |
I think I've long lost the branch I was working on for that. I'll have another go at it tomorrow, making a note to do that. ...ok, I guess I didnt do it... tomorrow for sure though :< |
Wasn't it opt-in before? based on the What are the correct semantics for this? |
anyways, test PR sent that fails without your patch and passes with it, that should be good enough |
It is opt-in in terms of the flag, but the If the PR for adding roles goes in, it should not add |
@caitp do you have a PR I can look at somewhere? I have submitted my code here: #10766 I added an array to the config so developers can change which elements receive keypress. I considered making a truthy |
@marcysutton I have a PR open aganst your ng-click fix branch |
you'd have to pick out parts of it manually, it's just a suggestion to get a test in there, but it looks like you've got some now |
Not wiring in the keypress handling for Am I testing this wrong, or should there be some handling for I'm using http://jsfiddle.net/8uu4kcq9/7/ (w/ angular-aria) and http://jsfiddle.net/bh2quo7c/5/ (w/o angular-aria) as my test scenarios, specifically the 4th |
@jorupp a valid
|
Also you should really use |
An anchor tag with an href (even an empty one) will fire a click upon an ENTER. That is accurate and expected. Button and input (type="submit", "button" or "image") will act the same as a button (fire click on ENTER or SPACE). |
Originally discussed here in pull #10288
Fix suggested by @marcysutton:
The text was updated successfully, but these errors were encountered: