Skip to content

Commit a4efa4b

Browse files
fix(IgxTimePicker): set displayValue to mask if no value is present #6494
1 parent 11067b4 commit a4efa4b

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

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

+25-2
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();
188198
fixture.detectChanges();
189199

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+
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;
@@ -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

+5-1
Original file line numberDiff line numberDiff line change
@@ -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;
@@ -1793,7 +1797,7 @@ export class IgxTimePickerComponent implements
17931797
*/
17941798
public cancelButtonClick(): void {
17951799
if (this.mode === InteractionMode.DropDown) {
1796-
this.displayValue = this._formatTime(this.value, this.format);
1800+
this.displayValue = this.value ? this._formatTime(this.value, this.format) : this.parseMask(false);
17971801
}
17981802

17991803
this.close();

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, 45, 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)