Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngAria): bind to keydown instead of keypress in ngClick #14065

Closed
wants to merge 5 commits into from
Closed

fix(ngAria): bind to keydown instead of keypress in ngClick #14065

wants to merge 5 commits into from

Conversation

LeeAdcock
Copy link
Contributor

The ngAria keyboard support for html elements used as button now binds to the keydown
event instead of keypress to better emulate behavior of native buttons.

BREAKING CHANGE: The ngAria configuration flag that controls binding to keyboard input
has been renamed from bindKeypress to bindKeydown so that it accurately describes the
implemented behavior.

Closes #14063

The ngAria keyboard support for html elements used as button now binds to the keydown
event instead of keypress to better emulate behavior of native buttons.

BREAKING CHANGE: The ngAria configuration flag that controls binding to keyboard input
has been renamed from `bindKeypress` to `bindKeydown` so that it accurately dscribes the
implemented behavior.

Closes #14063

expect(clickFn).toHaveBeenCalledWith('div');
expect(clickFn).toHaveBeenCalledWith('li');
});

it('should not override existing ng-keypress', function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove this test, just change it to use keydown instead.

@@ -364,8 +364,8 @@ ngAriaModule.directive('ngShow', ['$aria', function($aria) {
elem.attr('tabindex', 0);
}

if ($aria.config('bindKeypress') && !attr.ngKeypress) {
elem.on('keypress', function(event) {
if ($aria.config('bindKeydown') && !attr.ngKeypress) {
Copy link
Member

@gkalpak gkalpak Feb 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attr.ngKeypress should be also changed to attr.ngKeydown.
I wonder if it's a good idea to check for both (ngKeydown and ngKeypress).

@LeeAdcock
Copy link
Contributor Author

Thank you for your feedback @gkalpak, I've implemented changes as you suggested.

@gkalpak
Copy link
Member

gkalpak commented Feb 17, 2016

There is one remaining occurrence of keypress that needs to be changed to keydown in here.

And I still wonder if we should not do anything if the element does already have an ngKeydown/ngKeypress/ngKeyup (instead of only checking for ngKeydown). I mean, if the developer has placed both ngClick and one of the keyboard event handling directives on the element, they are clearly handling the keyboard interaction themselves, right.

I believe it would be best to leave them alone in that case, since they seem to know what they're doing.
WDYT @marcysutton ?

@gkalpak gkalpak self-assigned this Feb 17, 2016
@LeeAdcock
Copy link
Contributor Author

The more I think about it, the more I agree with you. It's clear the developer already has specific behavior in mind, that they have already implemented. Also, our willingness in this PR to switch from one key event to another signifies our opinion that in this context, they are not significantly different. It seems reasonable that we would not bind to key events if the user has already defined any custom key event behavior.

@LeeAdcock
Copy link
Contributor Author

@gkalpak any other feedback here?

@gkalpak
Copy link
Member

gkalpak commented Feb 25, 2016

@LeeAdcock, I didn't have time to take a look yet - will do in the next days.

@marcysutton
Copy link
Contributor

Looks good to me other than the documentation comment @gkalpak pointed out. I think it should just say "keydown event" since that's all it wires up–not keydown and keyup.

@gkalpak
Copy link
Member

gkalpak commented Jul 6, 2016

I would change bindKeyEvents to bindKeydown and the cos to just mention keydown event (because that's what we are binding to), but other than that LGTM (with a proper BC notice).

@gkalpak gkalpak closed this in ad41baa Jul 6, 2016
@gkalpak
Copy link
Member

gkalpak commented Jul 6, 2016

I made the necessary changes and merged 🎉
Thx @LeeAdcock for working on this!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants