Skip to content

Commit 88d0dcd

Browse files
authored
Merge pull request #6554 from IgniteUI/bpenkov/fix-6494-master
Determine initial min-max value
2 parents 11e82c1 + 146504e commit 88d0dcd

File tree

4 files changed

+59
-33
lines changed

4 files changed

+59
-33
lines changed

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

+48-25
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,32 @@ describe('IgxTimePicker', () => {
183183
expect(timePicker.onValidationFailed.emit).toHaveBeenCalled();
184184
}));
185185

186-
it('TimePicker cancel button', fakeAsync(() => {
186+
it('Should display mask on cancel button click with bound null value', fakeAsync(() => {
187187
const fixture = TestBed.createComponent(IgxTimePickerWithPmTimeComponent);
188+
fixture.componentInstance.dateValue = null;
189+
fixture.componentInstance.mode = 'dropdown';
190+
fixture.detectChanges();
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();
188203
fixture.detectChanges();
189204

205+
expect(timePicker.onValidationFailed.emit).not.toHaveBeenCalled();
206+
expect(timePicker.displayValue).toEqual('--:--:-- --');
207+
}));
208+
209+
it('TimePicker cancel button', fakeAsync(() => {
210+
const fixture = TestBed.createComponent(IgxTimePickerWithPmTimeComponent);
211+
fixture.detectChanges();
190212
const timePicker = fixture.componentInstance.timePicker;
191213
const dom = fixture.debugElement;
192214
const initialTime = dom.query(By.directive(IgxInputDirective)).nativeElement.value;
@@ -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', () => {
@@ -2024,12 +2046,13 @@ export class IgxTimePickerWithPassedTimeComponent {
20242046

20252047
@Component({
20262048
template: `
2027-
<igx-time-picker [value]="dateValue" [format]="customFormat"></igx-time-picker>
2049+
<igx-time-picker [mode]="mode" [value]="dateValue" [format]="customFormat"></igx-time-picker>
20282050
`
20292051
})
20302052
export class IgxTimePickerWithPmTimeComponent {
20312053
public dateValue: Date = new Date(2017, 7, 7, 12, 27, 23);
20322054
public customFormat = 'h:mm:ss tt';
2055+
public mode = 'dialog';
20332056
@ViewChild(IgxTimePickerComponent, { static: true }) public timePicker: IgxTimePickerComponent;
20342057
}
20352058

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

+9-6
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.parseMask(false)) {
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) {
@@ -1793,7 +1796,7 @@ export class IgxTimePickerComponent implements
17931796
*/
17941797
public cancelButtonClick(): void {
17951798
if (this.mode === InteractionMode.DropDown) {
1796-
this.displayValue = this._formatTime(this.value, this.format);
1799+
this.displayValue = this.value ? this._formatTime(this.value, this.format) : this.parseMask(false);
17971800
}
17981801

17991802
this.close();
@@ -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.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<h4 class="sample-title">Time Picker with Dropdown</h4>
88
<div class="sample-description">{{showDate(date)}}</div>
99
<div class="preview" style="width: 280px">
10-
<igx-time-picker #tp (onValueChanged)="valueChanged($event)"
10+
<igx-time-picker #tp (onValueChanged)="valueChanged($event)" [minValue]="'9:15 AM'" [maxValue]="'9:15 PM'"
1111
(onValidationFailed)="validationFailed($event)" [mode]="mode" [isSpinLoop]="isSpinLoop"
1212
[(ngModel)]="date" [itemsDelta]="itemsDelta" [format]="format">
1313
</igx-time-picker>

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

+1-1
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)