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

[Feature] - Add onClose callback #397

Merged
merged 1 commit into from
Apr 12, 2017
Merged

Conversation

rafacianci
Copy link
Contributor

This PR is related to #264

We are having some troubles when the user close the picker on the <DateRangePicker /> component, because it calls the onDatesChange and the onFocusChange at the same time, and when the onFocusChange is called without the focus there wasn't time to reset the state.

Copy link

@RaonyMarcondes RaonyMarcondes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏆

@coveralls
Copy link

Coverage Status

Coverage increased (+0.1%) to 87.468% when pulling 36a8af6 on viniciusdacal:issue-264 into b90ee78 on airbnb:master.

Copy link
Collaborator

@majapw majapw left a 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', () => {

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

@coveralls
Copy link

coveralls commented Apr 4, 2017

Coverage Status

Coverage increased (+0.3%) to 83.597% when pulling ad9be6a on viniciusdacal:issue-264 into 31d2764 on airbnb:master.

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,

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

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,
Copy link

@viniciusdacal viniciusdacal Apr 4, 2017

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

@@ -370,6 +375,8 @@ export default class DateRangePicker extends React.Component {
reopenPickerOnClearDates,
keepOpenOnDateSelect,
onDatesChange,
onFocusChange,

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?

Copy link
Member

@ljharb ljharb left a 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,

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

Copy link

@viniciusdacal viniciusdacal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🏆

@coveralls
Copy link

coveralls commented Apr 4, 2017

Coverage Status

Coverage increased (+0.3%) to 83.597% when pulling 8a13122 on viniciusdacal:issue-264 into 5ba9930 on airbnb:master.

@rafacianci
Copy link
Contributor Author

@ljharb and @majapw I updated the Pull Request, can you review it again? please...
thanks.

@coveralls
Copy link

coveralls commented Apr 4, 2017

Coverage Status

Coverage increased (+0.3%) to 83.597% when pulling 8a13122 on viniciusdacal:issue-264 into 5ba9930 on airbnb:master.

@@ -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);
Copy link
Member

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)

Copy link
Contributor Author

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);
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.. 👍

@rafacianci
Copy link
Contributor Author

done @ljharb.. can you review it?

@coveralls
Copy link

coveralls commented Apr 5, 2017

Coverage Status

Coverage increased (+0.3%) to 83.55% when pulling e4443d8 on viniciusdacal:issue-264 into 5ba9930 on airbnb:master.

if (!keepOpenOnDateSelect) this.props.onFocusChange(null);
if (!keepOpenOnDateSelect) {
onFocusChange(null);
this.props.onClose({ startDate, endDate });
Copy link
Member

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

Copy link
Contributor Author

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.. ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. @ljharb :D

Copy link
Member

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 :-)

Copy link
Contributor Author

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?

Copy link
Member

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 :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done @ljharb :)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 83.55% when pulling 06a40aa on viniciusdacal:issue-264 into 5ba9930 on airbnb:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 83.55% when pulling 06a40aa on viniciusdacal:issue-264 into 5ba9930 on airbnb:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 83.55% when pulling f84442e on viniciusdacal:issue-264 into 5ba9930 on airbnb:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 83.55% when pulling f84442e on viniciusdacal:issue-264 into 5ba9930 on airbnb:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.3%) to 83.55% when pulling e38362a on viniciusdacal:issue-264 into 5ba9930 on airbnb:master.

1 similar comment
@coveralls
Copy link

coveralls commented Apr 6, 2017

Coverage Status

Coverage increased (+0.3%) to 83.55% when pulling e38362a on viniciusdacal:issue-264 into 5ba9930 on airbnb:master.

Copy link
Member

@ljharb ljharb left a 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

@ljharb ljharb added the semver-minor: new stuff Any feature or API addition. label Apr 6, 2017
@rafacianci
Copy link
Contributor Author

@majapw can you review it?

Copy link
Collaborator

@majapw majapw left a 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! :)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 83.909% when pulling 527fa56 on viniciusdacal:issue-264 into f9370fb on airbnb:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 83.909% when pulling 527fa56 on viniciusdacal:issue-264 into f9370fb on airbnb:master.

@rafacianci
Copy link
Contributor Author

\o// thanks.. ☺️

@majapw
Copy link
Collaborator

majapw commented Apr 12, 2017

@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?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.2%) to 83.909% when pulling d7610b5 on viniciusdacal:issue-264 into f9370fb on airbnb:master.

@ljharb
Copy link
Member

ljharb commented Apr 12, 2017

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+.

@majapw
Copy link
Collaborator

majapw commented Apr 12, 2017

@ljharb Enzyme has a fix, I just need to add react-test-renderer to my deps according to @lelandrichardson, which I will do. :)

@majapw
Copy link
Collaborator

majapw commented Apr 12, 2017

PR open here - #442

@coveralls
Copy link

coveralls commented Apr 12, 2017

Coverage Status

Coverage increased (+0.2%) to 83.909% when pulling 4962f24 on viniciusdacal:issue-264 into 45eee40 on airbnb:master.

@majapw majapw merged commit 98232c3 into react-dates:master Apr 12, 2017
@lukedesu
Copy link

just pull the latest code and got a warning message like:
Warning: Unknown prop onClose on tag. Remove this prop from the element.

@ljharb
Copy link
Member

ljharb commented Apr 13, 2017

@senseluo filed as #444; fix incoming.

@haunguyen90
Copy link

great.... waiting for the update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor: new stuff Any feature or API addition.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants