Skip to content

Commit 2b70724

Browse files
authored
Bugfixes (#63)
* bugfix/issue62: fix format appearance * bugfix/issue61: fix touch events * feat(autofocus): add autofocus for timepicker dial control * update version
1 parent 490acd4 commit 2b70724

11 files changed

+100
-129
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to this project will be documented in this file
44

5+
## 2.8.3 (2018-11-02)
6+
7+
### Fixes
8+
9+
* fix(timepicker output): fix format appearance, closes [(#62)](https://github.com/Agranom/ngx-material-timepicker/issues/62)
10+
* fix(timepicker clock face): fix touch events, closes [(#61)](https://github.com/Agranom/ngx-material-timepicker/issues/61)
11+
* fix(timepicker dial): change focus on dial (hour <=> minute)
12+
513
## 2.8.2 (2018-10-29)
614

715
### Fixes

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ngx-material-timepicker",
33
"description": "Handy material design timepicker for angular",
4-
"version": "2.8.2",
4+
"version": "2.8.3",
55
"license": "MIT",
66
"author": "Vitalii Boiko <boyko330@gmail.com>",
77
"keywords": [

src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ <h3 class="ngx-material-timepicker-examples__title">Examples</h3>
175175
</main>
176176
<footer class="footer">
177177
<div class="container">
178-
<p class="footer__version">Current version 2.8.2</p>
178+
<p class="footer__version">Current version 2.8.3</p>
179179
</div>
180180
</footer>
181181
</div>

src/app/material-timepicker/components/timepicker-dial-control/ngx-material-timepicker-dial-control.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
<input class="timepicker-dial__control timepicker-dial__item"
33
[ngClass]="{'timepicker-dial__item_active': isActive, 'timepicker-dial__control_editable': isEditable}"
44
[(ngModel)]="time" (input)="updateTime()" (focus)="saveTimeAndChangeTimeUnit(timeUnit)"
5-
(blur)="revertTimeAndFormat()" [readonly]="!isEditable">
5+
(blur)="revertTimeAndFormat()" [readonly]="!isEditable" [timepickerAutofocus]="isActive">

src/app/material-timepicker/components/timepicker-face/ngx-material-timepicker-face.component.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
HostListener,
77
Input,
88
OnChanges,
9+
OnDestroy,
910
Output,
1011
SimpleChanges,
1112
ViewChild
@@ -29,7 +30,7 @@ const CLOCK_HAND_STYLES = {
2930
templateUrl: './ngx-material-timepicker-face.component.html',
3031
styleUrls: ['./ngx-material-timepicker-face.component.scss']
3132
})
32-
export class NgxMaterialTimepickerFaceComponent implements AfterViewInit, OnChanges {
33+
export class NgxMaterialTimepickerFaceComponent implements AfterViewInit, OnChanges, OnDestroy {
3334

3435
timeUnit = TimeUnit;
3536

@@ -49,9 +50,12 @@ export class NgxMaterialTimepickerFaceComponent implements AfterViewInit, OnChan
4950
@ViewChild('clockHand') clockHand: ElementRef;
5051

5152
private isStarted: boolean;
53+
private touchStartHandler: () => any;
54+
private touchEndHandler: () => any;
5255

5356
ngAfterViewInit() {
5457
this.setClockHandPosition();
58+
this.addTouchEvents();
5559
}
5660

5761
ngOnChanges(changes: SimpleChanges) {
@@ -77,7 +81,6 @@ export class NgxMaterialTimepickerFaceComponent implements AfterViewInit, OnChan
7781
return time.time;
7882
}
7983

80-
@HostListener('touchstart', ['$event'])
8184
@HostListener('mousedown', ['$event'])
8285
onMousedown(e: MouseEvent | TouchEvent) {
8386
e.preventDefault();
@@ -123,7 +126,6 @@ export class NgxMaterialTimepickerFaceComponent implements AfterViewInit, OnChan
123126

124127
}
125128

126-
@HostListener('touchend', ['$event'])
127129
@HostListener('mouseup', ['$event'])
128130
onMouseup(e: MouseEvent | TouchEvent) {
129131
e.preventDefault();
@@ -138,6 +140,23 @@ export class NgxMaterialTimepickerFaceComponent implements AfterViewInit, OnChan
138140
return ((this.selectedTime.time === minute) && (minute % (this.minutesGap || 5) === 0)) && !this.isClockFaceDisabled;
139141
}
140142

143+
ngOnDestroy() {
144+
this.removeTouchEvents();
145+
}
146+
147+
private addTouchEvents(): void {
148+
this.touchStartHandler = this.onMousedown.bind(this);
149+
this.touchEndHandler = this.onMouseup.bind(this);
150+
151+
this.clockFace.nativeElement.addEventListener('touchstart', this.touchStartHandler);
152+
this.clockFace.nativeElement.addEventListener('touchend', this.touchEndHandler);
153+
}
154+
155+
private removeTouchEvents(): void {
156+
this.clockFace.nativeElement.removeEventListener('touchstart', this.touchStartHandler);
157+
this.clockFace.nativeElement.removeEventListener('touchend', this.touchEndHandler);
158+
}
159+
141160
private setClockHandPosition(): void {
142161
if (this.format === 24) {
143162
if (this.selectedTime.time > 12 || this.selectedTime.time === '00') {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {Directive, ElementRef, Inject, Input, OnChanges, OnDestroy, Optional} from '@angular/core';
2+
import {DOCUMENT} from '@angular/common';
3+
4+
@Directive({
5+
selector: '[timepickerAutofocus]'
6+
})
7+
export class AutofocusDirective implements OnChanges, OnDestroy {
8+
9+
@Input('timepickerAutofocus') isFocusActive: boolean;
10+
11+
private activeElement: HTMLElement;
12+
13+
constructor(private element: ElementRef, @Optional() @Inject(DOCUMENT) private document: any) {
14+
this.activeElement = this.document.activeElement;
15+
}
16+
17+
ngOnChanges() {
18+
if (this.isFocusActive) {
19+
this.element.nativeElement.focus();
20+
}
21+
}
22+
23+
ngOnDestroy() {
24+
this.activeElement.focus();
25+
}
26+
}

src/app/material-timepicker/directives/focus-anchor.directive.spec.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/app/material-timepicker/directives/focus-anchor.directive.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/app/material-timepicker/directives/ngx-timepicker.directive.ts

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,18 @@ const VALUE_ACCESSOR = {
3030
},
3131
})
3232
export class TimepickerDirective implements ControlValueAccessor, OnDestroy, OnChanges {
33-
@Input()
34-
set value(value: string) {
35-
if (!value) {
36-
this._value = '';
37-
this.updateInputValue();
38-
return;
39-
}
40-
const time = TimeAdapter.formatTime(value, this._format);
41-
if (TimeAdapter.isTimeAvailable(time, <Moment>this._min, <Moment>this._max, 'minutes')) {
42-
this._value = time;
43-
this.updateInputValue();
44-
return;
45-
}
46-
console.warn('Selected time doesn\'t match min or max value');
47-
}
4833

49-
get value(): string {
50-
return this._value;
34+
@Input()
35+
set format(value: number) {
36+
this._format = value === 24 ? 24 : 12;
5137
}
5238

53-
private _value = '';
54-
5539
get format(): number {
5640
return this._format;
5741
}
5842

59-
@Input()
60-
set format(value: number) {
61-
this._format = value === 24 ? 24 : 12;
62-
}
63-
6443
private _format = 12;
6544

66-
get min(): string | Moment {
67-
return this._min;
68-
}
69-
7045
@Input()
7146
set min(value: string | Moment) {
7247
if (typeof value === 'string') {
@@ -76,12 +51,12 @@ export class TimepickerDirective implements ControlValueAccessor, OnDestroy, OnC
7651
this._min = value;
7752
}
7853

79-
private _min: string | Moment;
80-
81-
get max(): string | Moment {
82-
return this._max;
54+
get min(): string | Moment {
55+
return this._min;
8356
}
8457

58+
private _min: string | Moment;
59+
8560
@Input()
8661
set max(value: string | Moment) {
8762
if (typeof value === 'string') {
@@ -91,9 +66,33 @@ export class TimepickerDirective implements ControlValueAccessor, OnDestroy, OnC
9166
this._max = value;
9267
}
9368

69+
get max(): string | Moment {
70+
return this._max;
71+
}
72+
9473
private _max: string | Moment;
9574

75+
@Input()
76+
set value(value: string) {
77+
if (!value) {
78+
this._value = '';
79+
this.updateInputValue();
80+
return;
81+
}
82+
const time = TimeAdapter.formatTime(value, this._format);
83+
if (TimeAdapter.isTimeAvailable(time, <Moment>this._min, <Moment>this._max, 'minutes')) {
84+
this._value = time;
85+
this.updateInputValue();
86+
return;
87+
}
88+
console.warn('Selected time doesn\'t match min or max value');
89+
}
9690

91+
get value(): string {
92+
return this._value;
93+
}
94+
95+
private _value = '';
9796

9897
@Input('ngxTimepicker')
9998
set timepicker(picker: NgxMaterialTimepickerComponent) {

src/app/material-timepicker/ngx-material-timepicker.component.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<div class="timepicker-backdrop-overlay" *ngIf="isOpened" overlay></div>
22
<div class="timepicker-overlay" *ngIf="isOpened">
3-
<div class="timepicker" [@timepicker]="animationState" (@timepicker.done)="animationDone($event)" tabindex="0"
4-
focusAnchor>
3+
<div class="timepicker" [@timepicker]="animationState" (@timepicker.done)="animationDone($event)" tabindex="0">
54
<header class="timepicker__header">
65
<ngx-material-timepicker-dial [format]="format" [hour]="selectedHour?.time | timeFormatter: timeUnit.HOUR"
76
[minute]="selectedMinute?.time | timeFormatter: timeUnit.MINUTE"

0 commit comments

Comments
 (0)