Hacker0x01 / react-datepicker

A simple and reusable datepicker component for React
https://reactdatepicker.com/
MIT License
7.92k stars 2.23k forks source link

Time input on change works only with current Date, when date format is "h:mm" #3593

Open Scanerrr opened 2 years ago

Scanerrr commented 2 years ago

Describe the bug When working with date picker to manipulate time it is ignoring selected date prop

To Reproduce

  1. Initiate a component
    
    const tomorrow = new Date();
    tomorrow.setDate(today.getDate() + 1);
    const [startDate, setStartDate] = useState(tomorrow);

return <DatePicker selected={startDate} onChange={(date) => setStartDate(date)} showTimeSelect showTimeSelectOnly dateFormat="h:mm aa" timeFormat="h:mm aa" />


2. Click on rendered date picker component and change time by writing number in input
3. Change handler called and next value is for current date (It was date in future by default)

**Expected behavior**
When changing input value by writing any number new value should respect `selected` date prop

**Screenshots**
Initial state:
![image](https://user-images.githubusercontent.com/11576877/168441413-d90e7a06-a916-4d51-8565-90688cec2f32.png)

Open date picker and type number to input:
![image](https://user-images.githubusercontent.com/11576877/168441450-68c31df5-d5ae-48dc-8980-c88797c039e4.png)

**Desktop:**

- Browser chrome
- Version 4.6.0

**Additional context**
When changing time by selecting value from dropdown list it works as intended

I wrote a demo where you can see that problem

[https://codesandbox.io/s/upbeat-lake-xnc0se?file=/src/App.js](https://codesandbox.io/s/upbeat-lake-xnc0se?file=/src/App.js
)

UPD: I did find out that this behaviour is caused by dateFormat, in my case it only have time `h:mm aa`
github-actions[bot] commented 1 month ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 10 days.