Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting time with set_focus_date #52

Closed
armanpwnz opened this issue Mar 11, 2024 · 5 comments
Closed

Selecting time with set_focus_date #52

armanpwnz opened this issue Mar 11, 2024 · 5 comments

Comments

@armanpwnz
Copy link

armanpwnz commented Mar 11, 2024

Hi,

I select the date and time, then hide 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

@Feshchenko
Copy link
Contributor

Hey, @armanpwnz your link is not working

@armanpwnz
Copy link
Author

@Feshchenko
Copy link
Contributor

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

@armanpwnz
Copy link
Author

armanpwnz commented Apr 4, 2024

@Feshchenko
Copy link
Contributor

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants