-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(list-key-manager): prevent the default keyboard actions #2009
fix(list-key-manager): prevent the default keyboard actions #2009
Conversation
bf641cf
to
6868127
Compare
this.focusFirstItem(); | ||
break; | ||
case END: | ||
event.preventDefault(); |
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.
Instead of calling preventDefault
in each case, you can do:
onKeydown(event: KeyboardEvent): void {
switch (event.keyCode) {
case DOWN_ARROW:
this.focusNextItem();
break;
case UP_ARROW:
this.focusPreviousItem();
break;
case HOME:
this.focusFirstItem();
break;
case END:
this.focusLastItem();
break;
case TAB:
this._tabOut.next(null);
return;
default:
return;
}
event.preventDefault();
}
(see slider.ts
for an example)
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.
It's not supposed to be called when tabbing, though. I initially went with something similar but it broke the menu e2e tests.
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.
That's why the tab case has a return
(it does need a comment to point that out, though)
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.
Updated. Also added a unit test for tab, just in case.
R: @kara |
Calls preventDefault when handling keyboard events in the ListKeyManager. This avoids the user scrolling the page when using the arrow keys to navigate. Relates to angular#1999.
6868127
to
55a837d
Compare
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.
LGTM
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Calls preventDefault when handling keyboard events in the ListKeyManager. This avoids the user scrolling the page when using the arrow keys to navigate.
Relates to #1999.