@@ -50,7 +50,7 @@ import { ITimePickerResourceStrings } from '../core/i18n/time-picker-resources';
5050import { CurrentResourceStrings } from '../core/i18n/resources' ;
5151import { KEYS , CancelableBrowserEventArgs , IBaseEventArgs } from '../core/utils' ;
5252import { 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
5656let NEXT_ID = 0 ;
@@ -1944,9 +1944,12 @@ export class IgxTimePickerComponent implements
19441944 this . isNotEmpty = false ;
19451945
19461946 const oldVal = new Date ( this . value ) ;
1947-
1948- this . displayValue = '' ;
1949- this . value . setHours ( 0 , 0 ) ;
1947+ this . displayValue = this . parseMask ( false ) ;
1948+ requestAnimationFrame ( ( ) => {
1949+ this . _setCursorPosition ( 0 ) ;
1950+ } ) ;
1951+ // TODO: refactoring - this.value should be null #6585
1952+ this . value ?. setHours ( 0 , 0 , 0 ) ;
19501953
19511954 if ( oldVal . getTime ( ) !== this . value . getTime ( ) || this . isReset ( ) ) {
19521955 const args : IgxTimePickerValueChangedEventArgs = {
@@ -1964,35 +1967,35 @@ export class IgxTimePickerComponent implements
19641967 * @hidden
19651968 */
19661969 public onInput ( event ) : void {
1967- const val = event . target . value ;
1970+ const inputMask : string = event . target . value ;
19681971 const oldVal = new Date ( this . value ) ;
19691972
1970- this . isNotEmpty = val !== this . parseMask ( false ) ;
1973+ this . isNotEmpty = inputMask !== this . parseMask ( false ) ;
19711974
19721975 // handle cases where all empty positions (promts) are filled and we want to update
19731976 // 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 ) ;
1977+ if ( inputMask . indexOf ( this . promptChar ) === - 1 ) {
1978+ if ( this . _isEntryValid ( inputMask ) ) {
1979+ const newVal = this . convertMinMaxValue ( inputMask ) ;
19771980 if ( oldVal . getTime ( ) !== newVal . getTime ( ) ) {
19781981 this . value = newVal ;
19791982 }
19801983 } else {
19811984 const args : IgxTimePickerValidationFailedEventArgs = {
19821985 timePicker : this ,
1983- currentValue : val ,
1986+ currentValue : new Date ( inputMask ) ,
19841987 setThroughUI : false
19851988 } ;
19861989 this . onValidationFailed . emit ( args ) ;
19871990 }
19881991 // handle cases where the user deletes the display value (when pressing backspace or delete)
1989- } else if ( ! this . value || ! val || val === this . parseMask ( false ) ) {
1992+ } else if ( ! this . value || inputMask . length === 0 || ! this . isNotEmpty ) {
19901993 this . isNotEmpty = false ;
1991-
1992- this . value . setHours ( 0 , 0 ) ;
1993- this . displayValue = val ;
1994-
1995- if ( oldVal . getTime ( ) !== this . value . getTime ( ) || this . isReset ( ) ) {
1994+ // TODO: refactoring - this.value should be null #6585
1995+ this . value ? .setHours ( 0 , 0 , 0 ) ;
1996+ this . displayValue = inputMask ;
1997+ if ( oldVal . getTime ( ) !== this . value ?. getTime ( ) || this . isReset ( ) ) {
1998+ // TODO: Do not emit event when the editor is empty #6482
19961999 const args : IgxTimePickerValueChangedEventArgs = {
19972000 oldValue : oldVal ,
19982001 newValue : this . value
@@ -2019,7 +2022,7 @@ export class IgxTimePickerComponent implements
20192022 this . isNotEmpty = value !== '' ;
20202023 this . displayValue = value ;
20212024
2022- if ( value && value !== this . parseMask ( ) ) {
2025+ if ( value && ( value !== this . parseMask ( ) || value !== this . parseMask ( false ) ) ) {
20232026 if ( this . _isEntryValid ( value ) ) {
20242027 const newVal = this . convertMinMaxValue ( value ) ;
20252028 if ( ! this . value || this . value . getTime ( ) !== newVal . getTime ( ) ) {
@@ -2148,9 +2151,9 @@ export class IgxTimePickerComponent implements
21482151 // Workaround method for #8135
21492152 // TODO: It must be removed in #6482
21502153 private isReset ( ) : boolean {
2151- return this . value . getHours ( ) === 0
2152- && this . value . getMinutes ( ) === 0
2153- && this . value . getSeconds ( ) === 0 ;
2154+ return this . value ? .getHours ( ) === 0
2155+ && this . value ? .getMinutes ( ) === 0
2156+ && this . value ? .getSeconds ( ) === 0 ;
21542157 }
21552158}
21562159
0 commit comments