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

Adding a today modifier to DayPickerRangeController #213

Merged
merged 1 commit into from
Dec 19, 2016
Merged

Adding a today modifier to DayPickerRangeController #213

merged 1 commit into from
Dec 19, 2016

Conversation

ChristerGustavsson
Copy link
Contributor

fixes #211

@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) to 86.569% when pulling 3d643c2 on ChristerGustavsson:today-modifier into 3685662 on airbnb:master.

@@ -107,6 +107,7 @@ export default class DayPickerRangeController extends React.Component {
};

this.isTouchDevice = isTouchDevice();
this.today = moment();
Copy link
Member

Choose a reason for hiding this comment

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

Whether something is a touch device won't change, but "today" will - imagine a component created at 11:59PM. Let's not cache this value. Maybe it should be a prop that's a function that defaults to returning moment - that way, it can be invoked every render, but can be overridden for tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think just updating this value in componentWillUpdate will accomplish the same thing and create slightly fewer new moment objects... isToday is going to be called potentially hundreds of times per render.

Copy link
Member

Choose a reason for hiding this comment

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

Right but if the component isn't updated, yet the day ticks over, then what "today" is won't update. I think it needs to be called at least once per every render.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But componentWillUpdate does get called on every render, right?

Copy link
Member

Choose a reason for hiding this comment

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

No, I think it only gets called when the render results in a different DOM.

Copy link
Member

Choose a reason for hiding this comment

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

Either that, or when different props and state will be rendered - I'm not 100% sure.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Either that, or when different props and state will be rendered - I'm not 100% sure.

I guess I think this is fine because a hover on a day will update it. or clicking on basically any part of the component. Literally the only issue will be that, if you leave the DateRangePicker open, switch windows, and it becomes the next day, when you come back to it, it won't update the today highlighting until you interact with the component... I think this is okay for the fact that we'll only create a fraction of the moment() objects we would otherwise.

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 looks good! A couple of nits.

@@ -223,6 +224,10 @@ export default class DayPickerRangeController extends React.Component {
return isDayBlocked(day) || isOutsideRange(day) || this.doesNotMeetMinimumNights(day);
}

isToday(day) {
return day.isSame(this.today, 'day');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you change this to use the isSameDay helper method? It should already be included in this file I think and it protects slightly better against falsey values

@@ -107,6 +107,7 @@ export default class DayPickerRangeController extends React.Component {
};

this.isTouchDevice = isTouchDevice();
this.today = moment();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a concern about the datepicker being open for a while, or someone using it across day boundaries. Let's leave it in the constructor but also maybe update it in componentWillUpdate (reset it as this.today = moment() again there.

@majapw
Copy link
Collaborator

majapw commented Dec 14, 2016

So this is perfect and will add a CalendarMonth__day--today class to the current day that you can style on. I think we can leave it with no styling in the default version.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 86.589% when pulling bb14c5f on ChristerGustavsson:today-modifier into 3685662 on airbnb:master.

@majapw
Copy link
Collaborator

majapw commented Dec 15, 2016

Sweet! Can you rebase and the squash the commits down into one?

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 86.589% when pulling 866067e on ChristerGustavsson:today-modifier into 0b872b0 on airbnb:master.

@majapw
Copy link
Collaborator

majapw commented Dec 15, 2016

Once @ljharb gives his thumbs up, we'll get this in! :)

@majapw majapw merged commit ee5d219 into react-dates:master Dec 19, 2016
@majapw majapw added the semver-minor: new stuff Any feature or API addition. label Dec 19, 2016
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.

Maybe bring back modifiers on DateRangePicker
4 participants