Skip to content

Commit

Permalink
fix(rating): don't hijack Tab key navigation
Browse files Browse the repository at this point in the history
Broken since #2473, we prevent default ALL known keys from Key enum

Fixes #2895
  • Loading branch information
maxokorokov committed Dec 5, 2018
1 parent d5b7296 commit 4b05da1
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/rating/rating.ts
Expand Up @@ -13,7 +13,7 @@ import {
ChangeDetectorRef
} from '@angular/core';
import {NgbRatingConfig} from './rating-config';
import {toString, getValueInRange} from '../util/util';
import {getValueInRange} from '../util/util';
import {Key} from '../util/key';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';

Expand Down Expand Up @@ -142,27 +142,27 @@ export class NgbRating implements ControlValueAccessor,

handleKeyDown(event: KeyboardEvent) {
// tslint:disable-next-line:deprecation
const {which} = event;
if (Key[toString(which)]) {
event.preventDefault();

switch (which) {
case Key.ArrowDown:
case Key.ArrowLeft:
this.update(this.rate - 1);
break;
case Key.ArrowUp:
case Key.ArrowRight:
this.update(this.rate + 1);
break;
case Key.Home:
this.update(0);
break;
case Key.End:
this.update(this.max);
break;
}
switch (event.which) {
case Key.ArrowDown:
case Key.ArrowLeft:
this.update(this.rate - 1);
break;
case Key.ArrowUp:
case Key.ArrowRight:
this.update(this.rate + 1);
break;
case Key.Home:
this.update(0);
break;
case Key.End:
this.update(this.max);
break;
default:
return;
}

// note 'return' in default case
event.preventDefault();
}

ngOnChanges(changes: SimpleChanges) {
Expand Down

0 comments on commit 4b05da1

Please sign in to comment.