@@ -50,7 +50,7 @@ import { ITimePickerResourceStrings } from '../core/i18n/time-picker-resources';
50
50
import { CurrentResourceStrings } from '../core/i18n/resources' ;
51
51
import { KEYS , CancelableBrowserEventArgs , IBaseEventArgs } from '../core/utils' ;
52
52
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' ;
54
54
55
55
let NEXT_ID = 0 ;
56
56
const ITEMS_COUNT = 7 ;
@@ -1894,9 +1894,12 @@ export class IgxTimePickerComponent implements
1894
1894
this . isNotEmpty = false ;
1895
1895
1896
1896
const oldVal = new Date ( this . value ) ;
1897
-
1898
- this . displayValue = '' ;
1899
- this . value . setHours ( 0 , 0 ) ;
1897
+ this . displayValue = this . parseMask ( false ) ;
1898
+ requestAnimationFrame ( ( ) => {
1899
+ this . _setCursorPosition ( 0 ) ;
1900
+ } ) ;
1901
+ // TODO: refactoring - this.value should be null #6585
1902
+ this . value ?. setHours ( 0 , 0 , 0 ) ;
1900
1903
1901
1904
if ( oldVal . getTime ( ) !== this . value . getTime ( ) ) {
1902
1905
const args : IgxTimePickerValueChangedEventArgs = {
@@ -1914,35 +1917,35 @@ export class IgxTimePickerComponent implements
1914
1917
* @hidden
1915
1918
*/
1916
1919
public onInput ( event ) : void {
1917
- const val = event . target . value ;
1920
+ const inputMask : string = event . target . value ;
1918
1921
const oldVal = new Date ( this . value ) ;
1919
1922
1920
- this . isNotEmpty = val !== this . parseMask ( false ) ;
1923
+ this . isNotEmpty = inputMask !== this . parseMask ( false ) ;
1921
1924
1922
1925
// handle cases where all empty positions (promts) are filled and we want to update
1923
1926
// timepicker own value property if it is a valid Date
1924
- if ( val . indexOf ( this . promptChar ) === - 1 ) {
1925
- if ( this . _isEntryValid ( val ) ) {
1926
- const newVal = this . _convertMinMaxValue ( val ) ;
1927
+ if ( inputMask . indexOf ( this . promptChar ) === - 1 ) {
1928
+ if ( this . _isEntryValid ( inputMask ) ) {
1929
+ const newVal = this . _convertMinMaxValue ( inputMask ) ;
1927
1930
if ( oldVal . getTime ( ) !== newVal . getTime ( ) ) {
1928
1931
this . value = newVal ;
1929
1932
}
1930
1933
} else {
1931
1934
const args : IgxTimePickerValidationFailedEventArgs = {
1932
1935
timePicker : this ,
1933
- currentValue : val ,
1936
+ currentValue : new Date ( inputMask ) ,
1934
1937
setThroughUI : false
1935
1938
} ;
1936
1939
this . onValidationFailed . emit ( args ) ;
1937
1940
}
1938
1941
// handle cases where the user deletes the display value (when pressing backspace or delete)
1939
- } else if ( ! this . value || ! val || val === this . parseMask ( false ) ) {
1942
+ } else if ( ! this . value || inputMask . length === 0 || ! this . isNotEmpty ) {
1940
1943
this . isNotEmpty = false ;
1941
-
1942
- this . value . setHours ( 0 , 0 ) ;
1943
- this . displayValue = val ;
1944
-
1945
- if ( oldVal . getTime ( ) !== this . value . getTime ( ) ) {
1944
+ // TODO: refactoring - this.value should be null #6585
1945
+ this . value ? .setHours ( 0 , 0 , 0 ) ;
1946
+ this . displayValue = inputMask ;
1947
+ if ( oldVal . getTime ( ) !== this . value ?. getTime ( ) ) {
1948
+ // TODO: Do not emit event when the editor is empty #6482
1946
1949
const args : IgxTimePickerValueChangedEventArgs = {
1947
1950
oldValue : oldVal ,
1948
1951
newValue : this . value
@@ -1969,7 +1972,7 @@ export class IgxTimePickerComponent implements
1969
1972
this . isNotEmpty = value !== '' ;
1970
1973
this . displayValue = value ;
1971
1974
1972
- if ( value && value !== this . parseMask ( ) ) {
1975
+ if ( value && ( value !== this . parseMask ( ) || value !== this . parseMask ( false ) ) ) {
1973
1976
if ( this . _isEntryValid ( value ) ) {
1974
1977
const newVal = this . _convertMinMaxValue ( value ) ;
1975
1978
if ( ! this . value || this . value . getTime ( ) !== newVal . getTime ( ) ) {
0 commit comments