@@ -422,6 +422,45 @@ export class DatePicker extends Component<DatePickerProps, DatePickerState> {
422422 } ;
423423 } ;
424424
425+ getInputValue = ( ) : string => {
426+ const {
427+ locale,
428+ startDate,
429+ endDate,
430+ rangeSeparator,
431+ selected,
432+ selectedDates,
433+ selectsMultiple,
434+ selectsRange,
435+ value,
436+ } = this . props ;
437+ const dateFormat =
438+ this . props . dateFormat ?? DatePicker . defaultProps . dateFormat ;
439+
440+ const { inputValue } = this . state ;
441+
442+ if ( typeof value === "string" ) {
443+ return value ;
444+ } else if ( typeof inputValue === "string" ) {
445+ return inputValue ;
446+ } else if ( selectsRange ) {
447+ return safeDateRangeFormat ( startDate , endDate , {
448+ dateFormat,
449+ locale,
450+ rangeSeparator,
451+ } ) ;
452+ } else if ( selectsMultiple ) {
453+ return safeMultipleDatesFormat ( selectedDates ?? [ ] , {
454+ dateFormat,
455+ locale,
456+ } ) ;
457+ }
458+ return safeDateFormat ( selected , {
459+ dateFormat,
460+ locale,
461+ } ) ;
462+ } ;
463+
425464 resetHiddenStatus = ( ) : void => {
426465 this . setState ( {
427466 ...this . state ,
@@ -1268,8 +1307,9 @@ export class DatePicker extends Component<DatePickerProps, DatePickerState> {
12681307 } ;
12691308
12701309 renderAriaLiveRegion = ( ) => {
1271- const { dateFormat = DatePicker . defaultProps . dateFormat , locale } =
1272- this . props ;
1310+ const { locale } = this . props ;
1311+ const dateFormat =
1312+ this . props . dateFormat ?? DatePicker . defaultProps . dateFormat ;
12731313 const isContainsTime =
12741314 this . props . showTimeInput || this . props . showTimeSelect ;
12751315 const longDateFormat = isContainsTime ? "PPPPp" : "PPPP" ;
@@ -1345,35 +1385,12 @@ export class DatePicker extends Component<DatePickerProps, DatePickerState> {
13451385
13461386 const customInput = this . props . customInput || < input type = "text" /> ;
13471387 const customInputRef = this . props . customInputRef || "ref" ;
1348- const { dateFormat = DatePicker . defaultProps . dateFormat , locale } =
1349- this . props ;
1350-
1351- const inputValue =
1352- typeof this . props . value === "string"
1353- ? this . props . value
1354- : typeof this . state . inputValue === "string"
1355- ? this . state . inputValue
1356- : this . props . selectsRange
1357- ? safeDateRangeFormat ( this . props . startDate , this . props . endDate , {
1358- dateFormat,
1359- locale,
1360- rangeSeparator : this . props . rangeSeparator ,
1361- } )
1362- : this . props . selectsMultiple
1363- ? safeMultipleDatesFormat ( this . props . selectedDates ?? [ ] , {
1364- dateFormat,
1365- locale,
1366- } )
1367- : safeDateFormat ( this . props . selected , {
1368- dateFormat,
1369- locale,
1370- } ) ;
13711388
13721389 return cloneElement ( customInput , {
13731390 [ customInputRef ] : ( input : HTMLElement | null ) => {
13741391 this . input = input ;
13751392 } ,
1376- value : inputValue ,
1393+ value : this . getInputValue ( ) ,
13771394 onBlur : this . handleBlur ,
13781395 onChange : this . handleChange ,
13791396 onClick : this . onInputClick ,
0 commit comments