datepicker icon indicating copy to clipboard operation
datepicker copied to clipboard

Selecting time with set_focus_date

Open armanpwnz opened this issue 11 months ago • 4 comments

Hi,

I select the date and time, then hide <DateProvider> with the button, and then when I open it I can't select the time without the code like this:

useEffect(() => { dispatch({ type: "SET_FOCUS_DATE", date: selectedDates[0] }); }, [dispatch, selectedDates]);

https://codesandbox.io/p/devbox/time-selection-useeffect-wpz4dr?file=%2Fsrc%2Fcomponents%2Ftime.tsx here a example with a toggle button

Thanks

armanpwnz avatar Mar 11 '24 11:03 armanpwnz

Hey, @armanpwnz your link is not working

Feshchenko avatar Mar 21 '24 13:03 Feshchenko

@Feshchenko https://codesandbox.io/p/sandbox/time-selection-useeffect-wpz4dr should work

armanpwnz avatar Mar 21 '24 15:03 armanpwnz

Знімок екрана 2024-03-28 о 21 17 14 still not working 🤷

Feshchenko avatar Mar 28 '24 19:03 Feshchenko

@Feshchenko https://codesandbox.io/p/devbox/time-selection-useeffect-wpz4dr?file=%2Fsrc%2Fcomponents%2Ftime.tsx should work, sorry, I forgot to access the sandbox.

armanpwnz avatar Apr 04 '24 09:04 armanpwnz

Hey @armanpwnz, I hope you are doing well. What is happening in your example, the focusDate is the internal datepicker state. So when you hide and show it the state is lost, that's how React works. You have a focusDate prop in configuration. So what you need to do is to persist it outside of UI that will be hidden. Here is a link to Sanbox with a working example without useEffect and manual dispatch, (but your solution is also good)

Feshchenko avatar Aug 09 '24 10:08 Feshchenko