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

Added OutsideClickHandler component with onOutsideClick callback #666

Merged
merged 4 commits into from
Aug 14, 2017

Conversation

mattRoyten
Copy link

Corrected onOutsideClick functionality missing from the DayPickerSingleDateController component. This prop was within the defaultProps and now is properly applied.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 86.243% when pulling 06bc627 on mattRoyten:outsideClick into d32e9b3 on airbnb:master.

isRTL={isRTL}
/>
<OutsideClickHandler
onOutsideClick={onOutsideClick}
Copy link
Member

Choose a reason for hiding this comment

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

if onOutsideClick is omitted, should the DayPicker still be wrapped?

Copy link
Author

Choose a reason for hiding this comment

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

I do not see any negative impact if onOutsideClick is omitted. Are you thinking to conditionally wrap the DayPicker component depending on the onOutsideClick value?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that way if people don't want outside click behavior, they wouldn't incur any overhead.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 86.263% when pulling 601dd36 on mattRoyten:outsideClick into d32e9b3 on airbnb:master.

@mattRoyten
Copy link
Author

@ljharb - Updated PR with suggestion.

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.

Thanks - I was thinking more, not wrapping it at all rather than wrapping it in a div - you could store the DayPicker element in a variable, and then repeat that in both if/else code paths.

} = this.props;

const { currentMonth, visibleDays } = this.state;

const DayPickerWrapper = (onOutsideClick) ? OutsideClickHandler : 'div';
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 remove these unnecessary parents on the ternary conditionals.

} = this.props;

const { currentMonth, visibleDays } = this.state;

const DayPickerWrapper = (onOutsideClick) ? OutsideClickHandler : 'div';
const wrapperProps = (onOutsideClick) ? { onOutsideClick } : {};
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be needed; onOutsideClick={null} on a DOM element is a no-op.

@mattRoyten
Copy link
Author

@ljharb - Thanks for the feedback, updated PR.

@coveralls
Copy link

Coverage Status

Coverage decreased (-9.8%) to 76.633% when pulling 065d567 on mattRoyten:outsideClick into d12633f on airbnb:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-9.8%) to 76.633% when pulling 065d567 on mattRoyten:outsideClick into d12633f on airbnb:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 86.483% when pulling 2e6e9b3 on mattRoyten:outsideClick into d12633f on airbnb:master.

@majapw
Copy link
Collaborator

majapw commented Aug 9, 2017

I'm interested in why the refactor failed. I too think I would prefer what @ljharb suggested and don't know why that would cause tests to fail.

@mattRoyten
Copy link
Author

@majapw - all of the DayPickerSingleDateController tests were getting the following error:
Invariant Violation: Unexpected node: [object Object]

@ljharb
Copy link
Member

ljharb commented Aug 10, 2017

@mattRoyten You had an error in your code, in the unwrapped case, you were returning an object (ie, { dayPickerComponent } instead of directly returning dayPickerComponent.

Could you rebase on the command line so as to remove all merge commits, and also remove the last revert commit, and fix that error?

@mattRoyten
Copy link
Author

@ljharb - got it. Updated.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 86.43% when pulling 24662b8 on mattRoyten:outsideClick into 9685cc9 on airbnb:master.

ljharb
ljharb previously approved these changes Aug 10, 2017
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.

LGTM, but I'm deferring to @majapw

isRTL={isRTL}
/>
);
const dayPickerComponent = (<DayPicker
Copy link
Member

Choose a reason for hiding this comment

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

one last nit: the ( should end the line, and the ); should begin one - iow:

const foo = (
  <div>
  </div>
);

@ljharb ljharb requested a review from majapw August 10, 2017 16:50
@ljharb ljharb added the semver-minor: new stuff Any feature or API addition. label Aug 10, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.04%) to 86.43% when pulling e5855a6 on mattRoyten:outsideClick into 9685cc9 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.

Looks like we need some test coverage of this - a single shallow-render should do 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.

Let's add a test! :)

(one that checks for the presence of the OutsideClickHandler when that's passed in and for its absence when it's not should be sufficient)

@@ -599,6 +601,18 @@ export default class DayPickerSingleDateController extends React.Component {
isRTL={isRTL}
/>
);

if (onOutsideClick) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh this looks so much better

@mattRoyten
Copy link
Author

@majapw - tests added!

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 86.502% when pulling 7b59f4f on mattRoyten:outsideClick into 9685cc9 on airbnb:master.

ljharb
ljharb previously approved these changes Aug 11, 2017
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.

Looks great!

onOutsideClick={() => null}
/>,
);
expect(wrapper.find(OutsideClickHandler).length).to.equal(1);
Copy link
Member

Choose a reason for hiding this comment

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

expect(wrapper.find(OutsideClickHandler).to.have.lengthOf(1) has a nicer failure message; nbd tho :-)

Copy link
Author

Choose a reason for hiding this comment

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

sure, want me to change this as well?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, that'd be great :-D

Copy link
Author

Choose a reason for hiding this comment

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

done! 💥

majapw
majapw previously approved these changes Aug 11, 2017
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.

LGTM!

@mattRoyten mattRoyten dismissed stale reviews from majapw and ljharb via 8a328fb August 14, 2017 18:50
@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) to 86.502% when pulling 8a328fb on mattRoyten:outsideClick into 9685cc9 on airbnb:master.

@ljharb ljharb merged commit 57a0f37 into react-dates:master Aug 14, 2017
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.

5 participants