Add initialVisibleMonth fn prop to DayPicker#70
Conversation
test/components/DayPicker_spec.jsx
Outdated
| }); | ||
| }); | ||
|
|
||
| describe('#componentWillReceiveProps', () => { |
There was a problem hiding this comment.
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 calledmount()without a global document being loaded. when i remove skip
There was a problem hiding this comment.
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.
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.
|
@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. |
src/components/DayPicker.jsx
Outdated
| }; | ||
|
|
||
| const triggerInitialVisibleMonth = (props) => ( | ||
| props.hidden ? moment() : props.initialVisibleMonth() |
There was a problem hiding this comment.
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.
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.
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.
Since it's used in two separate components, my hope was that we'd define it in one place and import it in both.
| constructor(props) { | ||
| super(props); | ||
|
|
||
| this.hasSetInitialVisibleMonth = !props.hidden; |
There was a problem hiding this comment.
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 |
majapw
left a comment
There was a problem hiding this comment.
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. :)
| onNextMonthClick={onNextMonthClick} | ||
| monthFormat={monthFormat} | ||
| withPortal={withPortal || withFullScreenPortal} | ||
| hidden={!focusedInput} |
There was a problem hiding this comment.
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.
:( 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.
Man, I should really have read @ljharb's comments more carefully before. :) hidden sounds good to me
src/components/DayPicker.jsx
Outdated
| }; | ||
|
|
||
| const triggerInitialVisibleMonth = (props) => ( | ||
| props.hidden ? moment() : props.initialVisibleMonth() |
There was a problem hiding this comment.
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?
| onNextMonthClick={onNextMonthClick} | ||
| monthFormat={monthFormat} | ||
| withPortal={withPortal || withFullScreenPortal} | ||
| hidden={!focused} |
There was a problem hiding this comment.
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
| global: | ||
| statements: 89 | ||
| branches: 70 | ||
| branches: 69 |
There was a problem hiding this comment.
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