Skip to content

Commit 8fe8dfe

Browse files
fix(IgxTimePicker): determine initial min-max value #6494
1 parent a744ea0 commit 8fe8dfe

File tree

3 files changed

+55
-30
lines changed

3 files changed

+55
-30
lines changed

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

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,28 @@ describe('IgxTimePicker', () => {
183183
expect(timePicker.onValidationFailed.emit).toHaveBeenCalled();
184184
}));
185185

186+
it('Should not throw Validation Failed event with null value passed in', fakeAsync(() => {
187+
const fixture = TestBed.createComponent(IgxTimePickerWithPmTimeComponent);
188+
fixture.componentInstance.dateValue = null;
189+
fixture.detectChanges();
190+
191+
const timePicker = fixture.componentInstance.timePicker;
192+
const dom = fixture.debugElement;
193+
const timePickerTarget = dom.query(By.directive(IgxInputDirective));
194+
spyOn(timePicker.onValidationFailed, 'emit');
195+
196+
UIInteractions.clickElement(timePickerTarget);
197+
tick();
198+
fixture.detectChanges();
199+
200+
const cancelButton = dom.query(By.css('.igx-button--flat'));
201+
UIInteractions.clickElement(cancelButton);
202+
tick();
203+
fixture.detectChanges();
204+
205+
expect(timePicker.onValidationFailed.emit).not.toHaveBeenCalled();
206+
}));
207+
186208
it('TimePicker cancel button', fakeAsync(() => {
187209
const fixture = TestBed.createComponent(IgxTimePickerWithPmTimeComponent);
188210
fixture.detectChanges();
@@ -1613,34 +1635,34 @@ describe('IgxTimePicker', () => {
16131635
}));
16141636

16151637
it('When timepicker is closed via outside click, the focus should NOT remain on the input',
1616-
fakeAsync(() => {
1617-
fixture.detectChanges();
1618-
input = fixture.debugElement.query(By.directive(IgxInputDirective)).nativeElement;
1619-
let overlayToggle = document.getElementsByClassName('igx-overlay__wrapper');
1638+
fakeAsync(() => {
1639+
fixture.detectChanges();
1640+
input = fixture.debugElement.query(By.directive(IgxInputDirective)).nativeElement;
1641+
let overlayToggle = document.getElementsByClassName('igx-overlay__wrapper');
16201642

1621-
expect(overlayToggle.length).toEqual(0);
1643+
expect(overlayToggle.length).toEqual(0);
16221644

1623-
const iconTime = dom.queryAll(By.css('.igx-icon'))[0];
1624-
UIInteractions.clickElement(iconTime);
1625-
tick();
1626-
fixture.detectChanges();
1645+
const iconTime = dom.queryAll(By.css('.igx-icon'))[0];
1646+
UIInteractions.clickElement(iconTime);
1647+
tick();
1648+
fixture.detectChanges();
16271649

1628-
overlayToggle = document.getElementsByClassName('igx-overlay__wrapper');
1629-
expect(overlayToggle[0]).not.toBeNull();
1630-
expect(overlayToggle[0]).not.toBeUndefined();
1650+
overlayToggle = document.getElementsByClassName('igx-overlay__wrapper');
1651+
expect(overlayToggle[0]).not.toBeNull();
1652+
expect(overlayToggle[0]).not.toBeUndefined();
16311653

1632-
const dummyInput = fixture.componentInstance.dummyInput.nativeElement;
1633-
dummyInput.focus();
1634-
dummyInput.click();
1635-
tick();
1636-
fixture.detectChanges();
1654+
const dummyInput = fixture.componentInstance.dummyInput.nativeElement;
1655+
dummyInput.focus();
1656+
dummyInput.click();
1657+
tick();
1658+
fixture.detectChanges();
16371659

1638-
overlayToggle = document.getElementsByClassName('igx-overlay__wrapper');
1639-
input = fixture.debugElement.query(By.directive(IgxInputDirective)).nativeElement;
1640-
expect(overlayToggle[0]).toEqual(undefined);
1641-
expect(input).not.toEqual(document.activeElement);
1642-
expect(dummyInput).toEqual(document.activeElement);
1643-
}));
1660+
overlayToggle = document.getElementsByClassName('igx-overlay__wrapper');
1661+
input = fixture.debugElement.query(By.directive(IgxInputDirective)).nativeElement;
1662+
expect(overlayToggle[0]).toEqual(undefined);
1663+
expect(input).not.toEqual(document.activeElement);
1664+
expect(dummyInput).toEqual(document.activeElement);
1665+
}));
16441666
});
16451667

16461668
describe('Timepicker with outlet', () => {

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,9 +1305,9 @@ export class IgxTimePickerComponent implements
13051305
return false;
13061306
} else if (this.minValue && value < this._convertMinMaxValue(this.minValue)) {
13071307
return false;
1308-
} else {
1309-
return true;
13101308
}
1309+
1310+
return true;
13111311
}
13121312

13131313
private _isEntryValid(val: string): boolean {
@@ -1477,6 +1477,10 @@ export class IgxTimePickerComponent implements
14771477
const oldValue = this.value;
14781478
const newVal = this._convertMinMaxValue(this.displayValue);
14791479

1480+
if (!this.displayValue && this.displayValue === this._formatTime(this.value, this.format)) {
1481+
return;
1482+
}
1483+
14801484
if (this._isValueValid(newVal)) {
14811485
if (!this.value || oldValue.getTime() !== newVal.getTime()) {
14821486
this.value = newVal;
@@ -1514,7 +1518,6 @@ export class IgxTimePickerComponent implements
15141518
// use this flag to make sure that min/maxValue are checked (in _convertMinMaxValue() method)
15151519
// against the real value when initializing the component and value is bound via ngModel
15161520
this._dateFromModel = value;
1517-
15181521
this.value = value;
15191522

15201523
if (this.mode === InteractionMode.DropDown) {
@@ -1792,7 +1795,7 @@ export class IgxTimePickerComponent implements
17921795
* ```
17931796
*/
17941797
public cancelButtonClick(): void {
1795-
if (this.mode === InteractionMode.DropDown) {
1798+
if (this.mode === InteractionMode.DropDown && this.value) {
17961799
this.displayValue = this._formatTime(this.value, this.format);
17971800
}
17981801

@@ -2036,8 +2039,8 @@ export class IgxTimePickerComponent implements
20362039
}
20372040

20382041
// minor hack for preventing cursor jumping in IE
2039-
this._displayValue = this.inputFormat.transform(displayVal);
2040-
this.input.nativeElement.value = this._displayValue;
2042+
this.displayValue = this.inputFormat.transform(displayVal);
2043+
this.input.nativeElement.value = this.displayValue;
20412044
this._setCursorPosition(cursor);
20422045

20432046
requestAnimationFrame(() => {

src/app/time-picker/time-picker.sample.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class TimePickerSampleComponent implements AfterViewInit {
1717
mode = InteractionMode.DropDown;
1818

1919
date1 = new Date(2018, 10, 27, 17, 45, 0, 0);
20-
date = new Date(2018, 10, 27, 17, 45, 0, 0);
20+
date = new Date(2018, 10, 27, 21, 55, 0, 0);
2121
val = new Date(0, 0, 0, 19, 35, 30, 0);
2222
today = new Date(Date.now());
2323

0 commit comments

Comments
 (0)