@@ -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' ;
5454import { IgxLabelDirective } from '../directives/label/label.directive' ;
5555
5656
@@ -1951,9 +1951,12 @@ export class IgxTimePickerComponent implements
19511951 this . isNotEmpty = false ;
19521952
19531953 const oldVal = new Date ( this . value ) ;
1954-
1955- this . displayValue = '' ;
1956- this . value . setHours ( 0 , 0 ) ;
1954+ this . displayValue = this . parseMask ( false ) ;
1955+ requestAnimationFrame ( ( ) => {
1956+ this . _setCursorPosition ( 0 ) ;
1957+ } ) ;
1958+ // TODO: refactoring - this.value should be null #6585
1959+ this . value ?. setHours ( 0 , 0 , 0 ) ;
19571960
19581961 if ( oldVal . getTime ( ) !== this . value . getTime ( ) ) {
19591962 const args : IgxTimePickerValueChangedEventArgs = {
@@ -1971,35 +1974,35 @@ export class IgxTimePickerComponent implements
19711974 * @hidden
19721975 */
19731976 public onInput ( event ) : void {
1974- const val = event . target . value ;
1977+ const inputMask : string = event . target . value ;
19751978 const oldVal = new Date ( this . value ) ;
19761979
1977- this . isNotEmpty = val !== this . parseMask ( false ) ;
1980+ this . isNotEmpty = inputMask !== this . parseMask ( false ) ;
19781981
19791982 // handle cases where all empty positions (promts) are filled and we want to update
19801983 // timepicker own value property if it is a valid Date
1981- if ( val . indexOf ( this . promptChar ) === - 1 ) {
1982- if ( this . _isEntryValid ( val ) ) {
1983- const newVal = this . convertMinMaxValue ( val ) ;
1984+ if ( inputMask . indexOf ( this . promptChar ) === - 1 ) {
1985+ if ( this . _isEntryValid ( inputMask ) ) {
1986+ const newVal = this . convertMinMaxValue ( inputMask ) ;
19841987 if ( oldVal . getTime ( ) !== newVal . getTime ( ) ) {
19851988 this . value = newVal ;
19861989 }
19871990 } else {
19881991 const args : IgxTimePickerValidationFailedEventArgs = {
19891992 timePicker : this ,
1990- currentValue : val ,
1993+ currentValue : new Date ( inputMask ) ,
19911994 setThroughUI : false
19921995 } ;
19931996 this . onValidationFailed . emit ( args ) ;
19941997 }
19951998 // handle cases where the user deletes the display value (when pressing backspace or delete)
1996- } else if ( ! this . value || ! val || val === this . parseMask ( false ) ) {
1999+ } else if ( ! this . value || inputMask . length === 0 || ! this . isNotEmpty ) {
19972000 this . isNotEmpty = false ;
1998-
1999- this . value . setHours ( 0 , 0 ) ;
2000- this . displayValue = val ;
2001-
2002- if ( oldVal . getTime ( ) !== this . value . getTime ( ) ) {
2001+ // TODO: refactoring - this.value should be null #6585
2002+ this . value ? .setHours ( 0 , 0 , 0 ) ;
2003+ this . displayValue = inputMask ;
2004+ if ( oldVal . getTime ( ) !== this . value ?. getTime ( ) ) {
2005+ // TODO: Do not emit event when the editor is empty #6482
20032006 const args : IgxTimePickerValueChangedEventArgs = {
20042007 oldValue : oldVal ,
20052008 newValue : this . value
@@ -2026,7 +2029,7 @@ export class IgxTimePickerComponent implements
20262029 this . isNotEmpty = value !== '' ;
20272030 this . displayValue = value ;
20282031
2029- if ( value && value !== this . parseMask ( ) ) {
2032+ if ( value && ( value !== this . parseMask ( ) || value !== this . parseMask ( false ) ) ) {
20302033 if ( this . _isEntryValid ( value ) ) {
20312034 const newVal = this . convertMinMaxValue ( value ) ;
20322035 if ( ! this . value || this . value . getTime ( ) !== newVal . getTime ( ) ) {
0 commit comments