-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Feature] - Add onClose callback #397
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable to me. Can you added the same functionality to the SingleDatePicker, update the README, and squash your commits? I'll merge it in after that. :)
@@ -90,6 +90,25 @@ describe('DateRangePickerInputController', () => { | |||
wrapper.instance().onClearFocus(); | |||
expect(onFocusChangeStub.calledWith(null)).to.equal(true); | |||
}); | |||
|
|||
it('calls props.onFocusChange with startDate and endDate args', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think here it was supposed to be props.onClose
README.md
Outdated
@@ -171,6 +172,7 @@ navPrev: PropTypes.node, | |||
navNext: PropTypes.node, | |||
onPrevMonthClick: PropTypes.func, | |||
onNextMonthClick: PropTypes.func, | |||
onClose: ({ startDate, endDate }) => this.setState({ startDate, endDate }) // PropTypes.func, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't it be onclose: PropTypes.func
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put the function to let the user know how to use the callback... I didn't what would be the better way to show it. Any ideias?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
English text in the documentation. propTypes are not for a human, they're for React to issue warnings when it doesn't match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could set examples above, after line 77
README.md
Outdated
@@ -111,6 +111,7 @@ navPrev: PropTypes.node, | |||
navNext: PropTypes.node, | |||
onPrevMonthClick: PropTypes.func, | |||
onNextMonthClick: PropTypes.func, | |||
onClose: ({ startDate, endDate }) => this.setState({ startDate, endDate }) // PropTypes.func, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need the comment here? Same case line 175
src/components/DateRangePicker.jsx
Outdated
@@ -370,6 +375,8 @@ export default class DateRangePicker extends React.Component { | |||
reopenPickerOnClearDates, | |||
keepOpenOnDateSelect, | |||
onDatesChange, | |||
onFocusChange, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we using onFocusChange in this scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like you have a defaultProp inside propTypes by mistake?
README.md
Outdated
@@ -171,6 +172,7 @@ navPrev: PropTypes.node, | |||
navNext: PropTypes.node, | |||
onPrevMonthClick: PropTypes.func, | |||
onNextMonthClick: PropTypes.func, | |||
onClose: ({ startDate, endDate }) => this.setState({ startDate, endDate }) // PropTypes.func, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this one, would go after line 142
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🏆
@@ -123,7 +129,10 @@ export default class DateRangePickerInputController extends React.Component { | |||
!isInclusivelyBeforeDay(endDate, startDate); | |||
if (isEndDateValid) { | |||
onDatesChange({ startDate, endDate }); | |||
if (!keepOpenOnDateSelect) onFocusChange(null); | |||
if (!keepOpenOnDateSelect) { | |||
onFocusChange(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should call this.onClearFocus
instead? (To avoid repeating this pair of statements)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice.. :D
@@ -147,7 +149,10 @@ export default class DayPickerRangeController extends React.Component { | |||
this.props.onFocusChange(START_DATE); | |||
} else if (isInclusivelyAfterDay(day, firstAllowedEndDate)) { | |||
endDate = day; | |||
if (!keepOpenOnDateSelect) this.props.onFocusChange(null); | |||
if (!keepOpenOnDateSelect) { | |||
this.props.onFocusChange(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's destructure out these prop funcs so their this
isn't the props object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.. 👍
done @ljharb.. can you review it? |
if (!keepOpenOnDateSelect) this.props.onFocusChange(null); | ||
if (!keepOpenOnDateSelect) { | ||
onFocusChange(null); | ||
this.props.onClose({ startDate, endDate }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this would be destructured out too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh ok.. I didnt because it was using just so I thought it should be better to use the props.. But I removing.. ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. @ljharb :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variables are free; passing the props object to user code is not :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice.. :)
can you approve it?
and.. can I merge and squash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can always rebase down to an atomic set of commits; please do so frequently :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done @ljharb :)
1 similar comment
1 similar comment
1 similar comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good; deferring to @majapw
@majapw can you review it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Let's get her merged! :)
1 similar comment
\o// thanks.. |
@ljharb The new travis tests are failing in a weird way. Specifically there seems to be an error with installing enzyme when testing with React 15... Can you take a look? |
It's because React 15.5, due to new warnings, is a breaking change for us and for enzyme. The quick fix is to lock React down to < 15.5; pending the changes required to run the tests on both 15.4 and 15.5+. |
@ljharb Enzyme has a fix, I just need to add |
PR open here - #442 |
just pull the latest code and got a warning message like: |
@senseluo filed as #444; fix incoming. |
great.... waiting for the update |
This PR is related to #264
We are having some troubles when the user close the picker on the
<DateRangePicker />
component, because it calls theonDatesChange
and theonFocusChange
at the same time, and when theonFocusChange
is called without the focus there wasn't time to reset the state.