@@ -423,6 +423,41 @@ export default class DatePicker extends Component<
423
423
} ;
424
424
} ;
425
425
426
+ getInputValue = ( ) : string => {
427
+ const {
428
+ dateFormat = DatePicker . defaultProps . dateFormat ,
429
+ locale,
430
+ startDate,
431
+ endDate,
432
+ selected,
433
+ selectedDates,
434
+ selectsMultiple,
435
+ selectsRange,
436
+ value,
437
+ } = this . props ;
438
+ const { inputValue } = this . state ;
439
+
440
+ if ( typeof value === "string" ) {
441
+ return value ;
442
+ } else if ( typeof inputValue === "string" ) {
443
+ return inputValue ;
444
+ } else if ( selectsRange ) {
445
+ return safeDateRangeFormat ( startDate , endDate , {
446
+ dateFormat,
447
+ locale,
448
+ } ) ;
449
+ } else if ( selectsMultiple ) {
450
+ return safeMultipleDatesFormat ( selectedDates ?? [ ] , {
451
+ dateFormat,
452
+ locale,
453
+ } ) ;
454
+ }
455
+ return safeDateFormat ( selected , {
456
+ dateFormat,
457
+ locale,
458
+ } ) ;
459
+ } ;
460
+
426
461
resetHiddenStatus = ( ) : void => {
427
462
this . setState ( {
428
463
...this . state ,
@@ -1338,33 +1373,12 @@ export default class DatePicker extends Component<
1338
1373
1339
1374
const customInput = this . props . customInput || < input type = "text" /> ;
1340
1375
const customInputRef = this . props . customInputRef || "ref" ;
1341
- const { dateFormat = DatePicker . defaultProps . dateFormat , locale } =
1342
- this . props ;
1343
- const inputValue =
1344
- typeof this . props . value === "string"
1345
- ? this . props . value
1346
- : typeof this . state . inputValue === "string"
1347
- ? this . state . inputValue
1348
- : this . props . selectsRange
1349
- ? safeDateRangeFormat ( this . props . startDate , this . props . endDate , {
1350
- dateFormat,
1351
- locale,
1352
- } )
1353
- : this . props . selectsMultiple
1354
- ? safeMultipleDatesFormat ( this . props . selectedDates ?? [ ] , {
1355
- dateFormat,
1356
- locale,
1357
- } )
1358
- : safeDateFormat ( this . props . selected , {
1359
- dateFormat,
1360
- locale,
1361
- } ) ;
1362
1376
1363
1377
return cloneElement ( customInput , {
1364
1378
[ customInputRef ] : ( input : HTMLElement | null ) => {
1365
1379
this . input = input ;
1366
1380
} ,
1367
- value : inputValue ,
1381
+ value : this . getInputValue ( ) ,
1368
1382
onBlur : this . handleBlur ,
1369
1383
onChange : this . handleChange ,
1370
1384
onClick : this . onInputClick ,
0 commit comments