Skip to content

Commit 4671176

Browse files
authored
Merge pull request #8292 from IgniteUI/bpenkov/time-picker-onvaluechanged-9.1
Emit onValueChanged if 00:00 is cleared - 9.1.x
2 parents 85cc468 + 8392261 commit 4671176

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
@@ -1388,6 +1388,15 @@ describe('IgxTimePicker', () => {
13881388
expect(timePicker.onValidationFailed.emit).toHaveBeenCalled();
13891389
}));
13901390

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

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
@@ -1901,7 +1901,7 @@ export class IgxTimePickerComponent implements
19011901
// TODO: refactoring - this.value should be null #6585
19021902
this.value?.setHours(0, 0, 0);
19031903

1904-
if (oldVal.getTime() !== this.value.getTime()) {
1904+
if (oldVal.getTime() !== this.value?.getTime() || this.isReset()) {
19051905
const args: IgxTimePickerValueChangedEventArgs = {
19061906
oldValue: oldVal,
19071907
newValue: this.value
@@ -1944,7 +1944,7 @@ export class IgxTimePickerComponent implements
19441944
// TODO: refactoring - this.value should be null #6585
19451945
this.value?.setHours(0, 0, 0);
19461946
this.displayValue = inputMask;
1947-
if (oldVal.getTime() !== this.value?.getTime()) {
1947+
if (oldVal.getTime() !== this.value?.getTime() || this.isReset()) {
19481948
// TODO: Do not emit event when the editor is empty #6482
19491949
const args: IgxTimePickerValueChangedEventArgs = {
19501950
oldValue: oldVal,
@@ -2097,6 +2097,14 @@ export class IgxTimePickerComponent implements
20972097
input.valid = IgxInputState.INITIAL;
20982098
}
20992099
}
2100+
2101+
// Workaround method for #8135
2102+
// TODO: It must be removed in #6482
2103+
private isReset(): boolean {
2104+
return this.value?.getHours() === 0
2105+
&& this.value?.getMinutes() === 0
2106+
&& this.value?.getSeconds() === 0;
2107+
}
21002108
}
21012109

21022110
/**

0 commit comments

Comments
 (0)