-
-
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
Added OutsideClickHandler component with onOutsideClick callback #666
Conversation
isRTL={isRTL} | ||
/> | ||
<OutsideClickHandler | ||
onOutsideClick={onOutsideClick} |
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.
if onOutsideClick
is omitted, should the DayPicker still be wrapped?
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 do not see any negative impact if onOutsideClick
is omitted. Are you thinking to conditionally wrap the DayPicker component depending on the onOutsideClick
value?
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.
Yes, that way if people don't want outside click behavior, they wouldn't incur any overhead.
@ljharb - Updated PR with suggestion. |
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.
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'; |
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 remove these unnecessary parents on the ternary conditionals.
} = this.props; | ||
|
||
const { currentMonth, visibleDays } = this.state; | ||
|
||
const DayPickerWrapper = (onOutsideClick) ? OutsideClickHandler : 'div'; | ||
const wrapperProps = (onOutsideClick) ? { onOutsideClick } : {}; |
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 shouldn't be needed; onOutsideClick={null}
on a DOM element is a no-op.
@ljharb - Thanks for the feedback, updated PR. |
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. |
@majapw - all of the DayPickerSingleDateController tests were getting the following error: |
@mattRoyten You had an error in your code, in the unwrapped case, you were returning an object (ie, 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? |
2e6e9b3
to
24662b8
Compare
@ljharb - got it. Updated. |
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, but I'm deferring to @majapw
isRTL={isRTL} | ||
/> | ||
); | ||
const dayPickerComponent = (<DayPicker |
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.
one last nit: the (
should end the line, and the );
should begin one - iow:
const foo = (
<div>
</div>
);
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 like we need some test coverage of this - a single shallow-render should do 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.
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) { |
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.
Oh this looks so much better
@majapw - tests added! |
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!
onOutsideClick={() => null} | ||
/>, | ||
); | ||
expect(wrapper.find(OutsideClickHandler).length).to.equal(1); |
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.
expect(wrapper.find(OutsideClickHandler).to.have.lengthOf(1)
has a nicer failure message; nbd tho :-)
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.
sure, want me to change this as well?
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.
Sure, that'd be great :-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.
done! 💥
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!
Corrected onOutsideClick functionality missing from the DayPickerSingleDateController component. This prop was within the defaultProps and now is properly applied.