Skip to content

Commit a24c2c0

Browse files
fix(time-picker): set mask to editor on clear
1 parent 8086251 commit a24c2c0

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,9 +1852,11 @@ describe('IgxTimePicker', () => {
18521852
UIInteractions.simulateClickAndSelectEvent(clearTime);
18531853
fixture.detectChanges();
18541854
input.nativeElement.dispatchEvent(new Event('focus'));
1855+
tick();
18551856
fixture.detectChanges();
18561857

18571858
input.nativeElement.dispatchEvent(new Event('blur'));
1859+
tick();
18581860
fixture.detectChanges();
18591861

18601862
expect(input.nativeElement.value).toEqual('');
@@ -1866,6 +1868,21 @@ describe('IgxTimePicker', () => {
18661868
expect(input.nativeElement.value).toBe('-- AM');
18671869
}));
18681870

1871+
it('should allow editing of input after clear', fakeAsync(() => {
1872+
fixture.componentInstance.format = 'hh tt';
1873+
fixture.componentInstance.customDate = new Date(2018, 10, 27, 17, 45, 0, 0);
1874+
fixture.detectChanges();
1875+
spyOn(fixture.componentInstance.timePicker, 'onInput');
1876+
1877+
const clearTime = dom.queryAll(By.css('.igx-icon'))[1];
1878+
UIInteractions.simulateClickAndSelectEvent(clearTime);
1879+
fixture.detectChanges();
1880+
const _input = fixture.debugElement.query(By.css('input'));
1881+
UIInteractions.simulateTyping('12 AM', _input);
1882+
expect(fixture.componentInstance.timePicker.onInput).not.toThrow();
1883+
expect(_input.nativeElement.value).toEqual('12 AM');
1884+
}));
1885+
18691886
it('Should navigate dropdown lists correctly when format contains only hours.', fakeAsync(() => {
18701887
fixture.componentInstance.format = 'hh tt';
18711888
fixture.componentInstance.customDate = new Date(2018, 10, 27, 17, 45, 0);

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import { ITimePickerResourceStrings } from '../core/i18n/time-picker-resources';
5050
import { CurrentResourceStrings } from '../core/i18n/resources';
5151
import { KEYS, CancelableBrowserEventArgs, IBaseEventArgs } from '../core/utils';
5252
import { InteractionMode } from '../core/enums';
53-
import { IgxTextSelectionModule} from '../directives/text-selection/text-selection.directive';
53+
import { IgxTextSelectionModule } from '../directives/text-selection/text-selection.directive';
5454

5555

5656
let NEXT_ID = 0;
@@ -1945,7 +1945,11 @@ export class IgxTimePickerComponent implements
19451945

19461946
const oldVal = new Date(this.value);
19471947

1948-
this.displayValue = '';
1948+
this.displayValue = this.parseMask(false);
1949+
requestAnimationFrame(() => {
1950+
this._setCursorPosition(0);
1951+
});
1952+
// TODO: refactoring - this.value should be null #8135
19491953
this.value.setHours(0, 0);
19501954

19511955
if (oldVal.getTime() !== this.value.getTime()) {
@@ -1964,33 +1968,34 @@ export class IgxTimePickerComponent implements
19641968
* @hidden
19651969
*/
19661970
public onInput(event): void {
1967-
const val = event.target.value;
1971+
const inputMask = event.target.value;
19681972
const oldVal = new Date(this.value);
19691973

1970-
this.isNotEmpty = val !== this.parseMask(false);
1974+
this.isNotEmpty = inputMask !== this.parseMask(false);
19711975

19721976
// handle cases where all empty positions (promts) are filled and we want to update
19731977
// timepicker own value property if it is a valid Date
1974-
if (val.indexOf(this.promptChar) === -1) {
1975-
if (this._isEntryValid(val)) {
1976-
const newVal = this.convertMinMaxValue(val);
1978+
if (inputMask.indexOf(this.promptChar) === -1) {
1979+
if (this._isEntryValid(inputMask)) {
1980+
const newVal = this.convertMinMaxValue(inputMask);
19771981
if (oldVal.getTime() !== newVal.getTime()) {
19781982
this.value = newVal;
19791983
}
19801984
} else {
19811985
const args: IgxTimePickerValidationFailedEventArgs = {
19821986
timePicker: this,
1983-
currentValue: val,
1987+
currentValue: inputMask,
19841988
setThroughUI: false
19851989
};
19861990
this.onValidationFailed.emit(args);
19871991
}
19881992
// handle cases where the user deletes the display value (when pressing backspace or delete)
1989-
} else if (!this.value || !val || val === this.parseMask(false)) {
1993+
} else if (inputMask === this.parseMask(false)) {
19901994
this.isNotEmpty = false;
19911995

1996+
// TODO: refactoring - this.value should be null #8135
19921997
this.value.setHours(0, 0);
1993-
this.displayValue = val;
1998+
this.displayValue = inputMask;
19941999

19952000
if (oldVal.getTime() !== this.value.getTime()) {
19962001
const args: IgxTimePickerValueChangedEventArgs = {

0 commit comments

Comments
 (0)