@@ -230,7 +230,7 @@ export const FormatMixin = dedupeMixin(
230230 // imperatively, we DO want to format a value (it is the only way to get meaningful
231231 // input into `.inputElement` with modelValue as input)
232232
233- if ( this . __isHandlingUserInput && this . errorState ) {
233+ if ( this . __isHandlingUserInput && this . errorState && this . inputElement ) {
234234 return this . inputElement ? this . value : undefined ;
235235 }
236236 return this . formatter ( this . modelValue , this . formatOptions ) ;
@@ -335,8 +335,6 @@ export const FormatMixin = dedupeMixin(
335335 // is guaranteed to be calculated
336336 setTimeout ( this . _reflectBackFormattedValueToUser ) ;
337337 } ;
338- this . inputElement . addEventListener ( this . formatOn , this . _reflectBackFormattedValueDebounced ) ;
339- this . inputElement . addEventListener ( 'input' , this . _proxyInputEvent ) ;
340338 this . addEventListener ( 'user-input-changed' , this . _onUserInputChanged ) ;
341339 // Connect the value found in <input> to the formatting/parsing/serializing loop as a
342340 // fallback mechanism. Assume the user uses the value property of the
@@ -347,16 +345,26 @@ export const FormatMixin = dedupeMixin(
347345 this . _syncValueUpwards ( ) ;
348346 }
349347 this . _reflectBackFormattedValueToUser ( ) ;
348+
349+ if ( this . inputElement ) {
350+ this . inputElement . addEventListener (
351+ this . formatOn ,
352+ this . _reflectBackFormattedValueDebounced ,
353+ ) ;
354+ this . inputElement . addEventListener ( 'input' , this . _proxyInputEvent ) ;
355+ }
350356 }
351357
352358 disconnectedCallback ( ) {
353359 super . disconnectedCallback ( ) ;
354- this . inputElement . removeEventListener ( 'input' , this . _proxyInputEvent ) ;
355360 this . removeEventListener ( 'user-input-changed' , this . _onUserInputChanged ) ;
356- this . inputElement . removeEventListener (
357- this . formatOn ,
358- this . _reflectBackFormattedValueDebounced ,
359- ) ;
361+ if ( this . inputElement ) {
362+ this . inputElement . removeEventListener ( 'input' , this . _proxyInputEvent ) ;
363+ this . inputElement . removeEventListener (
364+ this . formatOn ,
365+ this . _reflectBackFormattedValueDebounced ,
366+ ) ;
367+ }
360368 }
361369 } ,
362370) ;
0 commit comments