Reputation: 2027
How to disable the up arrow key when a button is focused and enable it when the button is not focused in angular2? For example:
In html:
<button type="button" (focus)="disableUpArrowKey()">
In script:
disableUpArrowKey(){
//??
}
Upvotes: 0
Views: 1403
Reputation: 8241
Bind on keydown
and call preventDefault
of event.
html:
<button (keydown)="onKeydown($event)">Button</button>
ts:
...
onKeydown(event: KeyboardEvent) {
if (event.key === 'ArrowUp') {
event.preventDefault()
}
}
...
stackblitz : https://stackblitz.com/edit/angular-xmzct5
Upvotes: 2