-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
datepicker-keymap-service.ts
62 lines (58 loc) · 1.83 KB
/
datepicker-keymap-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import {Injectable} from '@angular/core';
import {NgbDatepickerService} from './datepicker-service';
import {NgbCalendar} from './ngb-calendar';
import {Key} from '../util/key';
import {NgbDate} from './ngb-date';
@Injectable()
export class NgbDatepickerKeyMapService {
private _minDate: NgbDate;
private _maxDate: NgbDate;
private _firstViewDate: NgbDate;
private _lastViewDate: NgbDate;
constructor(private _service: NgbDatepickerService, private _calendar: NgbCalendar) {
_service.model$.subscribe(model => {
this._minDate = model.minDate;
this._maxDate = model.maxDate;
this._firstViewDate = model.firstDate;
this._lastViewDate = model.lastDate;
});
}
processKey(event: KeyboardEvent) {
// tslint:disable-next-line:deprecation
switch (event.which) {
case Key.PageUp:
this._service.focusMove(event.altKey ? 'y' : 'm', -1);
break;
case Key.PageDown:
this._service.focusMove(event.altKey ? 'y' : 'm', 1);
break;
case Key.End:
this._service.focus(event.altKey ? this._maxDate : this._lastViewDate);
break;
case Key.Home:
this._service.focus(event.altKey ? this._minDate : this._firstViewDate);
break;
case Key.ArrowLeft:
this._service.focusMove('d', -1);
break;
case Key.ArrowUp:
this._service.focusMove('d', -this._calendar.getDaysPerWeek());
break;
case Key.ArrowRight:
this._service.focusMove('d', 1);
break;
case Key.ArrowDown:
this._service.focusMove('d', this._calendar.getDaysPerWeek());
break;
case Key.Enter:
case Key.Space:
this._service.focusSelect();
break;
default:
return;
}
// note 'return' in default case
event.preventDefault();
event.stopPropagation();
}
}