-
-
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
Add initialVisibleMonth fn prop to DayPicker #70
Conversation
@@ -260,6 +261,20 @@ describe('DayPicker', () => { | |||
}); | |||
}); | |||
|
|||
describe('#componentWillReceiveProps', () => { |
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 test can't run currently because of https://github.com/airbnb/react-dates/blob/master/test/components/DayPicker_spec.jsx#L225
Is there an open issue/discussion for how to solve? getting It looks like you called
mount()without a global document being loaded.
when i remove skip
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.
Yeah, at Airbnb we use jsdom afaict and mocha-wrap
(https://github.com/ljharb/mocha-wrap) plugin, but I think there was some discussion on what we plan to do for our open-source repos. @ljharb do you have thoughts on getting enzym's mount
to work in this repo? I haven't really thought about it, but we should really open an issue I guess.
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.
In order to do that, we'd need to run the test suite twice - once with jsdom, and once without it - and be able to mark tests that require the DOM such that they'd be skipped when running without jsdom.
I don't yet have a clean solution for this; i think it's OK to skip those tests for now.
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.
Yeah let's skip them.
@ljharb fixes added, let me know if you have more insight into the |
also the linter is failing because of https://github.com/airbnb/react-dates/pull/70/files#diff-883056b4b11263241c339f927e93411bR75 the issue is that if I make it one line I get Is the expected style below? const triggerInitialVisibleMonth = (props) =>
props.hidden ? moment() :
props.initialVisibleMonth(); |
const triggerInitialVisibleMonth = ({ hidden, initialVisibleMonth }) => (
hidden ? moment() : initialVisibleMonth()
); |
@ljharb whoops, totally spaced on that, good call :) |
Any reason the tests that are failing wouldn't be running/failing on my local machine? |
@travisbloom yes - rebase on latest master; one of the dependencies had to be locked down to avoid a bug. |
@@ -68,11 +72,17 @@ const defaultProps = { | |||
monthFormat: 'MMMM YYYY', | |||
}; | |||
|
|||
const triggerInitialVisibleMonth = (props) => ( | |||
props.hidden ? moment() : props.initialVisibleMonth() |
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'm not sure that we need this logic to be perfectly honest. The constructor is only called once and even if the datepicker is visible at that point, it will be the first time its ever rendered so I think we can just set state.currentMonth
to props.initialVisibleMonth()
. What is the edge case this is trying to solve?
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.
Can we pull this as an instance method onto the class, named as getInitialVisibleMonth
or something? That way we just have access to the props straight up.
Actually we don't even call this more than once. Why don't we just have this logic directly in the constructor?
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.
Oh sorry about that! I think if it's only used once, we should not pull it out. :) Let's go with that.
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.
Since it's used in two separate components, my hope was that we'd define it in one place and import it in both.
export default class DayPicker extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.hasSetInitialVisibleMonth = !props.hidden; |
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.
Similarly I don't think we need the hasSetInitialVisibleMonth
logic either.
Hey @travisbloom, this is looking good, but I'm a bit confused about the constructor logic you've included. |
@majapw my understanding was we only want Now that I think about it, it would prob be better to trigger it every time it opens...is that the expected behavior you were thinking? |
if thats the case, I'd propose changing |
Hmm, let me review again with that in mind. I guess the We can maybe augment it in the future to do kind of a fully controlled |
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.
Hi @travisbloom, sorry for the long delay in getting this out the door. Let's leave the implementation as is, but address the small nits in this review. After that I'm happy to merge this in ASAP. :)
@@ -361,6 +364,8 @@ export default class DateRangePicker extends React.Component { | |||
onNextMonthClick={onNextMonthClick} | |||
monthFormat={monthFormat} | |||
withPortal={withPortal || withFullScreenPortal} | |||
hidden={!focusedInput} |
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.
Can we change this name to isVisible
instead of hidden
? I think that is more in line with the other nomenclature in these files.
I think once we move to react-with-styles
, we hopefully won't need this anyways. since the component will be unmounted/remounted every time.
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.
:( unfortunately I had it named as visible before but @ljharb asked to change it to be hidden so we didn't have a boolean prop that defaulted to true.
Let me know what you would prefer now.
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.
Man, I should really have read @ljharb's comments more carefully before. :) hidden
sounds good to me
@@ -68,11 +72,17 @@ const defaultProps = { | |||
monthFormat: 'MMMM YYYY', | |||
}; | |||
|
|||
const triggerInitialVisibleMonth = (props) => ( | |||
props.hidden ? moment() : props.initialVisibleMonth() |
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.
Can we pull this as an instance method onto the class, named as getInitialVisibleMonth
or something? That way we just have access to the props straight up.
Actually we don't even call this more than once. Why don't we just have this logic directly in the constructor?
@@ -204,6 +208,8 @@ export default class SingleDatePicker extends React.Component { | |||
onNextMonthClick={onNextMonthClick} | |||
monthFormat={monthFormat} | |||
withPortal={withPortal || withFullScreenPortal} | |||
hidden={!focused} |
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.
same, let's name this as isVisible
We'll also need to rebase before getting this out! :D Thanks so much @travisbloom |
ed808c5
to
81e0c95
Compare
Adds a new prop to DateRangePicker, SingleDatePicker, and DayPicker that passes a fn to DayPicker. On the initial focus, that fn will be called and set the initial month to the returned moment object. solves issue react-dates#17
@@ -11,6 +11,6 @@ instrumentation: | |||
check: | |||
global: | |||
statements: 89 | |||
branches: 70 | |||
branches: 69 |
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.
inline with #70 (comment), updating coverage requirements
Great! Thank you for all of this @travisbloom. |
Adds a new prop to DateRangePicker, SingleDatePicker, and DayPicker
that passes a fn to DayPicker. On the initial focus, that fn will be called
and set the initial month to the returned moment object.
solves issue #17