Skip to content

Commit 40a2972

Browse files
authored
Merge pull request #8291 from IgniteUI/bpenkov/time-picker-onvaluechanged-10.1
Emit onValueChanged if 00:00 is cleared - 10.1.x
2 parents 4a7749d + c52b609 commit 40a2972

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

projects/igniteui-angular/src/lib/time-picker/time-picker.component.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,15 @@ describe('IgxTimePicker', () => {
13891389
expect(timePicker.onValidationFailed.emit).toHaveBeenCalled();
13901390
}));
13911391

1392+
it('should trigger onValueChanged if 00:00 is cleared from the input', () => {
1393+
fixture.componentInstance.date = new Date(2018, 10, 27, 0, 0, 0, 0);
1394+
fixture.detectChanges();
1395+
spyOn(timePicker.onValueChanged, 'emit');
1396+
timePicker.clear();
1397+
fixture.detectChanges();
1398+
expect(timePicker.onValueChanged.emit).toHaveBeenCalledTimes(1);
1399+
});
1400+
13921401
it('should scroll on dropdown opened and accept value when focus lost', fakeAsync(() => {
13931402
fixture.detectChanges();
13941403

projects/igniteui-angular/src/lib/time-picker/time-picker.component.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,7 +1951,7 @@ export class IgxTimePickerComponent implements
19511951
// TODO: refactoring - this.value should be null #6585
19521952
this.value?.setHours(0, 0, 0);
19531953

1954-
if (oldVal.getTime() !== this.value.getTime()) {
1954+
if (oldVal.getTime() !== this.value?.getTime() || this.isReset()) {
19551955
const args: IgxTimePickerValueChangedEventArgs = {
19561956
oldValue: oldVal,
19571957
newValue: this.value
@@ -1994,7 +1994,7 @@ export class IgxTimePickerComponent implements
19941994
// TODO: refactoring - this.value should be null #6585
19951995
this.value?.setHours(0, 0, 0);
19961996
this.displayValue = inputMask;
1997-
if (oldVal.getTime() !== this.value?.getTime()) {
1997+
if (oldVal.getTime() !== this.value?.getTime() || this.isReset()) {
19981998
// TODO: Do not emit event when the editor is empty #6482
19991999
const args: IgxTimePickerValueChangedEventArgs = {
20002000
oldValue: oldVal,
@@ -2147,6 +2147,14 @@ export class IgxTimePickerComponent implements
21472147
input.valid = IgxInputState.INITIAL;
21482148
}
21492149
}
2150+
2151+
// Workaround method for #8135
2152+
// TODO: It must be removed in #6482
2153+
private isReset(): boolean {
2154+
return this.value?.getHours() === 0
2155+
&& this.value?.getMinutes() === 0
2156+
&& this.value?.getSeconds() === 0;
2157+
}
21502158
}
21512159

21522160
/**

0 commit comments

Comments
 (0)