-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Added a way to open / close the calendar outside of the datepicker component #1048
Conversation
The test fails with / without my commit, what can I do about it? |
Would you mind making it clearer that this is adding another way to open/close the component from outside? (It can already be set statefully via the the I'm all for allowing the state to be fully controlled via props, but in that case, the prop should always take precedence if it is specified. Otherwise we end up with confusing behavior, like the datepicker closes itself despite having IE, we should use the value of the prop instead of treating it as an edge-trigger to toggle internal state. |
@aij Since there are a lot of users for this library, we didn't want to break any existing behavior.
So in each case, we make sure the state and the prop are in correlation. The "react way" will be to delete the state.open boolean, and to work only with the props.isOpen, but we should remember to have backward compatibility. This is our solution, but there is an alternative one, like you suggested, to completely ignore the state.open if the props.isOpen was given. I personally like the first solution better, but we are open for discussion. |
@lbelinsk When we call |
I agree with @aij; to summarize the requirements:
|
I understand what you mean with the confusing behaviour, theoretically That said, it's only to explain our approach about the problematic behaviour you described.
The bigger the component will get, the harder it will be to maintain that 2 scenarios, I think in the long run it will cause that different developed attributes will work great alone, but might not work too well with different combinations because developers will overlook this new open-state-prop mutation. After considering this and the example with the checkbox (that teach developers how to use the callback appropriately and maintain correlation between the prop.isOpen and state.open), advise which solution you prefer and I will change it accordingly. Thanks. |
I disagree with this -- if you choose to override the default behavior, you are giving up the automatic handling of open/close state. You can decide how to update the |
As @GBT3101 said before, we will go with the approach you will see best.
IMHO, It feels like the user has too much control in his hands like he has 2 separated components, Calendar popup and an input which he needs to sync together from scratch. Other than that, the user can decide to modify the external state with "onSelect" or "onChange" callbacks, which is fine. Please let us know what is the final solution. We will make sure to implement it tomorrow according to your decision. Thanks for the quick responses, it is really appreciated. |
Possibly related question: In my experience, the calendar closes by default when a date is selected. When |
@micahalcorn we have discussed about 2 possible solutions:
@rafeememon @aij can you confirm that the desired solution is the second one? |
@lbelinsk I was thinking closer to 1, but making it so TBH, I'm not sure how useful it is to control the openness of the calendar via props. It seems kind of akin to controlling focus via props, which React has decided not to do. It's not quite the same, because it never makes sense to have two inputs have focus at the same time but it might make sense to have more than one datepicker render as open at the same time, though I expect that would require other code changes as we've made assumptions that kind of tied calendar openness to focus. I think we have some confusion in this discussion due to the original comment (and commit message) being slightly misleading. (See my first comment where I requested that be clarified.) In case it wasn't clear enough earlier, the datepicker can already be opened and closed from outside the component, by calling Of course, calling Perhaps another source of confusion is that this PR is adding a new That said, I still don't understand the motivation for this PR (other than perhaps misunderstanding what is already possible -- which is hopefully clearer now). Is it just about being able to open or close the calendar externally? Then perhaps the new example could be updated to use the existing API. Does someone need callbacks in order to respond to the opening/closing of the calendar? Then it seems the new Does someone need to take control over when the calendar opens or closes? Then we could add the Perhaps an example might help. This page shows how we are using react-datepicker at CCAP: https://wccabeta.wicourts.gov/lawEnforcementCalendar.html Note how clicking the little calendar buttons opens and focuses the corresponding datepicker. That is of course already possible. Now could someone elaborate on what it is that Wix is trying to do? (And perhaps how that is different from what the existing API allows?) |
@aij thanks for your response. Use case: We implemented it on our side by placing Regarding this comment:
We thought about it in the beginning, but then we understood that there is one problem with this solution. Let's say we have a closed calendar. Now let's change @aij I completely agree with you that it is similar to Having said that, You guys are the watchers over the wall, and if this solution is not the one you want to go with then let's just roll back to the existing solution |
Hey, so after this long conversation, what solution are we going to pursue?
|
Let's go with (1) -- as you called out, the other solution adds confusion to the behavior and seems like one step forward and two steps backward. IMO, the |
Cool, so number 1 it is... |
Hi,
I work at Wix, and we needed a way to open / close the calendar outside of the component (for example, opening the calendar with an external button).
I've done that by adding 2 new props: "isOpen" (boolean) and "setOpen" (function).
This functionality will only work by adding these props, and will not affect the object in any way if those props were not added.
isOpen - will live alongside the internal ‘state.open’ in correlation.
setOpen - is a callback that will be called if the function is defined and the state has been changed.
I've also added a simple example that shows a connection between the calendar and a checkbox using this new feature.
Hope you will like it, have a nice week.
approved by @lbelinsk