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

Prop isOpen does not control opened state of calendar #59

Open
leo-iomer opened this issue Mar 28, 2018 · 11 comments
Open

Prop isOpen does not control opened state of calendar #59

leo-iomer opened this issue Mar 28, 2018 · 11 comments
Assignees
Labels
enhancement New feature or request fresh

Comments

@leo-iomer
Copy link

Based on the description and naming of the isOpen prop it is expected that if the isOpen prop is passed to the component the isOpen prop will control the open/closed state of the calendar. However, that is not the case and the component will open/close regardless of isOpen.

From my testing isOpen appears to work like a trigger and will open/close the calendar if isOpen changes and the calendar isn't already in the implied state of the prop.

@wojtekmaj
Copy link
Owner

In other words, isOpen only works when changed, but initial value is ignored?

@wojtekmaj wojtekmaj self-assigned this Mar 29, 2018
@wojtekmaj wojtekmaj added the bug Something isn't working label Mar 29, 2018
@leo-iomer
Copy link
Author

Not quite, if I initially set the isOpen to true the component will mount in the open state but on clicking outside of the calendar (or selecting a date) the calendar will transition to the closed state. In order to use the prop to reopen you then need to toggle isOpen prop to false then back to true to change the calendar back to the open state.

@wojtekmaj wojtekmaj added question Further information is requested and removed bug Something isn't working labels Mar 29, 2018
@wojtekmaj
Copy link
Owner

I see. That's actually very interesting case. An edge case IMO. Forcing this state to be always matching the one from props instead of being updated on mount and on prop change would make it impossible to use the calendar easily.

What would I suggest is rendering react-calendar yourself next to your date picker and make both components connected by yourself. In fact, that's what DatePicker.jsx is doing: It's wrapping DateInput component and Calendar component and keeps them in sync. What you need is just our own version of it in which onChange method is not closing the calendar.

While DateInput itself is internal component which is not documented, I can guarantee to it it is not a subject to change in any forseeable future, so you can safely use this custom wrapper for a long time!

@leo-iomer
Copy link
Author

Then in my opinion isOpen would is named incorrectly, a more accurate naming would be something like triggerOpen from my perspective.

I haven't had time to look into the internal workings of the component to see how difficult to implement this but adding in additional props onRequestCalendarClose and onRequestCalendarOpen props as function which would be called when the calendar would normally open/close would let calendar be used easily and have isOpen actually control the state of the calendar. Additionally this change would also bring the date picker in line with a lot of other components that maintain a open/closed state that I have run into such as modals.

@wojtekmaj
Copy link
Owner

I think that's an awesome idea. Would you please share some example implementation in some popular solution?

@leo-iomer
Copy link
Author

While I can't immediately think of a example that uses something like a "onOpen" or "onRequestOpen" here are two modal components that maintain the open state using a "isOpen" and "onDismiss"/"onRequestClose":

@wojtekmaj
Copy link
Owner

wojtekmaj commented Apr 4, 2018

Thank you! That makes it more clear for me.

@wojtekmaj wojtekmaj added the enhancement New feature or request label Apr 4, 2018
@chenasraf
Copy link

I agree with @leo-iomer - this is a really weird design choice. onClose or something of the likes is NECESSARY if you derive open state from props, because there needs to be a bounce back to update the parent state back to closed. As this currently is, this package became useless for my use case on the grounds of a single props which is also pretty much the most basic prop of them all.

The calendar literally can't be re-opened.

@akkharolia
Copy link

You need to set initial state of isOpen state variable to true and then update the same on onCalendarOpen. change state of isOpen variable after success of onChange.
Here is my code:
this.state={openDatePicker:true}
handleChange(){this.setState{openDatePicker:false}}
<DatePicker isOpen={this.state.openDatePicker} onCalendarOpen={() => this.setState({openDatePicker:true})} onChange={this.handleChange} />

@github-actions
Copy link
Contributor

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

@github-actions github-actions bot added the stale label Jan 24, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2022

This issue was closed because it has been stalled for 14 days with no activity.

@github-actions github-actions bot closed this as completed Feb 7, 2022
@wojtekmaj wojtekmaj added fresh and removed stale question Further information is requested labels Feb 7, 2022
@wojtekmaj wojtekmaj reopened this Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fresh
Projects
None yet
Development

No branches or pull requests

4 participants