react-datetime icon indicating copy to clipboard operation
react-datetime copied to clipboard

Close overlay with closeOnSelect if open prop is set

Open danrot opened this issue 5 years ago • 6 comments

Description

I have adjusted the logic happening when the onCloseSelect prop is set. It now also calls the onClose callback if the open prop is set to some value.

Motivation and Context

In v2 of this library we were using this component somehow like this (simplified example):

<ReactDateTime
    closeOnSelect={true}
    onClose={this.handleClose}
    open={this.props.open}
/>

This doesn't seem to work anymore in v3, because the closeOnSelect prop does not have any effect if any value other than undefined is passed to the open prop.

If this PR is accepted, the handleClose method will be called as expected. It is still in control of the rendering component if it changes the value passed to the open prop, in case that was a concern.

Checklist

[ ] I have not included any built dist files (us maintainers do that prior to a new release)
[x] I have added tests covering my changes
[x] All new and existing tests pass
[ ] My changes required the documentation to be updated
  [ ] I have updated the documentation accordingly
  [ ] I have updated the TypeScript 1.8 type definitions accordingly
  [ ] I have updated the TypeScript 2.0+ type definitions accordingly

danrot avatar Oct 05 '20 15:10 danrot

The checklist says I should not include any built dist files, but if I don't the tests and therefore the precommit hook fail :confused:

danrot avatar Oct 05 '20 15:10 danrot

@arqex Any chance that this is merged? This is a breaking change, that would force me to rewrite quite a bit of my application logic.

danrot avatar Oct 13 '20 07:10 danrot

@danrot You can use onChange prop for your purpose, like this:

<ReactDateTime
    onChange={this.handleClose}
	{...otherProps}
/>

onlined avatar Oct 15 '20 20:10 onlined

@onlined I know that I could rewrite it this way, that's what I meant in my previous comment :slightly_smiling_face: I would just like to avoid it, and I still think that the behavior "fixed" in this PR is very confusing, and it was working differently in a previous version. In addition to that I cannot see how anybody would benefit from that change, so I guess it was on accident.

danrot avatar Oct 16 '20 06:10 danrot

@arqex any update to this?

alexander-schranz avatar Apr 22 '21 20:04 alexander-schranz

@onlined the problem with the onChange is that it also close automatically then when the time is changed and thats a behaviour you don't want e.g.:

datetime-picker

alexander-schranz avatar Apr 23 '21 12:04 alexander-schranz