Skip to content

Commit b5f8978

Browse files
authored
Merge pull request #8290 from IgniteUI/bpenkov/time-picker-onvaluechanged
Emit onValueChanged if 00:00 is cleared
2 parents 4f3e66e + 48d48a5 commit b5f8978

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
@@ -1416,6 +1416,15 @@ describe('IgxTimePicker', () => {
14161416
expect(timePicker.onValidationFailed.emit).toHaveBeenCalled();
14171417
}));
14181418

1419+
it('should trigger onValueChanged if 00:00 is cleared from the input', () => {
1420+
fixture.componentInstance.date = new Date(2018, 10, 27, 0, 0, 0, 0);
1421+
fixture.detectChanges();
1422+
spyOn(timePicker.onValueChanged, 'emit');
1423+
timePicker.clear();
1424+
fixture.detectChanges();
1425+
expect(timePicker.onValueChanged.emit).toHaveBeenCalledTimes(1);
1426+
});
1427+
14191428
it('should scroll on dropdown opened and accept value when focus lost', fakeAsync(() => {
14201429
fixture.detectChanges();
14211430

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

1961-
if (oldVal.getTime() !== this.value.getTime()) {
1961+
if (oldVal.getTime() !== this.value?.getTime() || this.isReset()) {
19621962
const args: IgxTimePickerValueChangedEventArgs = {
19631963
oldValue: oldVal,
19641964
newValue: this.value
@@ -2001,7 +2001,7 @@ export class IgxTimePickerComponent implements
20012001
// TODO: refactoring - this.value should be null #6585
20022002
this.value?.setHours(0, 0, 0);
20032003
this.displayValue = inputMask;
2004-
if (oldVal.getTime() !== this.value?.getTime()) {
2004+
if (oldVal.getTime() !== this.value?.getTime() || this.isReset()) {
20052005
// TODO: Do not emit event when the editor is empty #6482
20062006
const args: IgxTimePickerValueChangedEventArgs = {
20072007
oldValue: oldVal,
@@ -2154,6 +2154,14 @@ export class IgxTimePickerComponent implements
21542154
input.valid = IgxInputState.INITIAL;
21552155
}
21562156
}
2157+
2158+
// Workaround method for #8135
2159+
// TODO: It must be removed in #6482
2160+
private isReset(): boolean {
2161+
return this.value?.getHours() === 0
2162+
&& this.value?.getMinutes() === 0
2163+
&& this.value?.getSeconds() === 0;
2164+
}
21572165
}
21582166

21592167
/**

0 commit comments

Comments
 (0)