Hacker0x01 / react-datepicker

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

TimeInput refreshes date to current date #4864

Open Siminn-teiturg opened 3 weeks ago

Siminn-teiturg commented 3 weeks ago

I already have a date and time selected. When I open the picker and start typing into the time input, the date will refresh and display the current date. I have a screen recording below to demonstrate.

<DatePicker
  selected={
    new Date(sportInputFields.broadcast_start_time)
  }
  onChange={(date) => {
    setSportInputFields({
      ...sportInputFields,
      broadcast_start_time: date.toISOString(),
    });
  }}
  showTimeInput={true}
  dateFormat="dd/MM/yyyy - HH:mm"
/>

https://github.com/Hacker0x01/react-datepicker/assets/84858035/9571ce7e-8723-4db8-8f81-4fc55d28353b

balajis-qb commented 3 weeks ago

Hi @Siminn-teiturg , I couldn't recreate the issue you mentioned. Can you please try it in the official website playground - https://reactdatepicker.com/#example-input-time

I tried with the code you shared, but it's working as expected

() => {
  const [startDate, setStartDate] = useState(new Date());
  return (
    <DatePicker
    selected={startDate}
    onChange={(date) => {
      setStartDate(date);
    }}
    showTimeInput={true}
    dateFormat="dd/MM/yyyy - HH:mm"
    />
  );
};

If you still have the issue, please share the code