@@ -220,7 +220,8 @@ class TimeSelect extends Component<TimeSelectProps, TimeSelectState> {
220220 : initialOptions ,
221221 isShowingOptions : false ,
222222 highlightedOptionId : initialSelection ? initialSelection . id : undefined ,
223- selectedOptionId : initialSelection ? initialSelection . id : undefined
223+ selectedOptionId : initialSelection ? initialSelection . id : undefined ,
224+ isInputCleared : false
224225 }
225226 }
226227
@@ -338,7 +339,8 @@ class TimeSelect extends Component<TimeSelectProps, TimeSelectState> {
338339 selectedOptionId : this . isControlled
339340 ? this . state . selectedOptionId
340341 : undefined ,
341- fireChangeOnBlur : undefined
342+ fireChangeOnBlur : undefined ,
343+ isInputCleared : value === '' ? true : false
342344 } )
343345 }
344346 this . setState ( {
@@ -386,7 +388,7 @@ class TimeSelect extends Component<TimeSelectProps, TimeSelectState> {
386388 // when pressing ESC. NOT called when an item is selected via Enter/click,
387389 // (but in this case it will be called later when the input is blurred.)
388390 handleBlurOrEsc : SelectProps [ 'onRequestHideOptions' ] = ( event ) => {
389- const { selectedOptionId, inputValue } = this . state
391+ const { selectedOptionId, inputValue, isInputCleared } = this . state
390392 let defaultValue = ''
391393 if ( this . props . defaultValue ) {
392394 const date = DateTime . parse (
@@ -400,14 +402,13 @@ class TimeSelect extends Component<TimeSelectProps, TimeSelectState> {
400402 }
401403 const selectedOption = this . getOption ( 'id' , selectedOptionId )
402404 let newInputValue = defaultValue
403- if ( selectedOption ) {
404- // If there is a selected option use its value in the input field.
405- newInputValue = selectedOption . label
406- }
407405 // if input was completely cleared, ensure it stays clear
408406 // e.g. defaultValue defined, but no selection yet made
409- else if ( inputValue === '' ) {
407+ if ( inputValue === '' ) {
410408 newInputValue = ''
409+ } else if ( selectedOption ) {
410+ // If there is a selected option use its value in the input field.
411+ newInputValue = selectedOption . label
411412 }
412413 this . setState ( ( ) => ( {
413414 isShowingOptions : false ,
@@ -421,6 +422,12 @@ class TimeSelect extends Component<TimeSelectProps, TimeSelectState> {
421422 value : this . state . fireChangeOnBlur . value . toISOString ( ) ,
422423 inputText : this . state . fireChangeOnBlur . label
423424 } )
425+ } else if ( isInputCleared && ( event as any ) . key !== 'Escape' ) {
426+ this . setState ( ( ) => ( { isInputCleared : false } ) )
427+ this . props . onChange ?.( event , {
428+ value : '' ,
429+ inputText : ''
430+ } )
424431 }
425432 // TODO only fire this if handleSelectOption was not called before.
426433 this . props . onHideOptions ?.( event )
0 commit comments