@@ -422,6 +422,45 @@ export class DatePicker extends Component<DatePickerProps, DatePickerState> {
422
422
} ;
423
423
} ;
424
424
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
+
425
464
resetHiddenStatus = ( ) : void => {
426
465
this . setState ( {
427
466
...this . state ,
@@ -1268,8 +1307,9 @@ export class DatePicker extends Component<DatePickerProps, DatePickerState> {
1268
1307
} ;
1269
1308
1270
1309
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 ;
1273
1313
const isContainsTime =
1274
1314
this . props . showTimeInput || this . props . showTimeSelect ;
1275
1315
const longDateFormat = isContainsTime ? "PPPPp" : "PPPP" ;
@@ -1345,35 +1385,12 @@ export class DatePicker extends Component<DatePickerProps, DatePickerState> {
1345
1385
1346
1386
const customInput = this . props . customInput || < input type = "text" /> ;
1347
1387
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
- } ) ;
1371
1388
1372
1389
return cloneElement ( customInput , {
1373
1390
[ customInputRef ] : ( input : HTMLElement | null ) => {
1374
1391
this . input = input ;
1375
1392
} ,
1376
- value : inputValue ,
1393
+ value : this . getInputValue ( ) ,
1377
1394
onBlur : this . handleBlur ,
1378
1395
onChange : this . handleChange ,
1379
1396
onClick : this . onInputClick ,
0 commit comments