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

Fixes some small feature bugs introduced in v11 #489

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion css/CalendarDay.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
box-sizing: border-box;

&:active {
background: darken($react-dates-color-white, 5%);
outline: 0;
}
}
Expand Down Expand Up @@ -88,6 +87,10 @@
background: $react-dates-color-primary-shade-4;
border: 1px double $react-dates-color-primary-shade-3;
color: $react-dates-color-secondary;

&:active {
background: $react-dates-color-primary-shade-3;
}
}

.CalendarDay--selected-start,
Expand Down
73 changes: 54 additions & 19 deletions src/components/DayPickerRangeController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,19 @@ export default class DayPickerRangeController extends React.Component {
this.modifiers['highlighted-calendar'] = day => isDayHighlighted(day);
}

const didStartDateChange = startDate !== this.props.startDate;
const didEndDateChange = endDate !== this.props.endDate;
const didFocusChange = focusedInput !== this.props.focusedInput;

if (
initialVisibleMonth !== this.props.initialVisibleMonth ||
numberOfMonths !== this.props.numberOfMonths ||
enableOutsideDays !== this.props.enableOutsideDays
(
initialVisibleMonth !== this.props.initialVisibleMonth ||
numberOfMonths !== this.props.numberOfMonths ||
enableOutsideDays !== this.props.enableOutsideDays
) && (
!this.props.focusedInput &&
didFocusChange
)
) {
const newMonthState = this.getStateForNewMonth(nextProps);
const currentMonth = newMonthState.currentMonth;
Expand All @@ -208,10 +217,6 @@ export default class DayPickerRangeController extends React.Component {
});
}

const didStartDateChange = startDate !== this.props.startDate;
const didEndDateChange = endDate !== this.props.endDate;
const didFocusChange = focusedInput !== this.props.focusedInput;

let modifiers = {};

if (didStartDateChange) {
Expand All @@ -228,8 +233,8 @@ export default class DayPickerRangeController extends React.Component {
if (this.props.startDate && this.props.endDate) {
modifiers = this.deleteModifierFromRange(
modifiers,
this.props.startDate.clone().add(1, 'day'),
this.props.endDate,
this.props.startDate,
this.props.endDate.clone().add(1, 'day'),
'selected-span',
);
}
Expand All @@ -251,12 +256,19 @@ export default class DayPickerRangeController extends React.Component {
}
}

if (didStartDateChange && startDate && !endDate) {
const startSpan = startDate.clone().add(1, 'day');
const endSpan = startDate.clone().add(minimumNights + 1, 'days');
modifiers = this.addModifierToRange(modifiers, startSpan, endSpan, 'after-hovered-start');
}

if (minimumNights > 0 || minimumNights !== this.props.minimumNights) {
if (this.props.startDate && (didFocusChange || didStartDateChange)) {
if (didFocusChange || didStartDateChange) {
const startSpan = this.props.startDate ? this.props.startDate : this.today;
modifiers = this.deleteModifierFromRange(
modifiers,
this.props.startDate,
this.props.startDate.clone().add(minimumNights, 'days'),
startSpan,
startSpan.clone().add(minimumNights, 'days'),
'blocked-minimum-nights',
);
}
Expand Down Expand Up @@ -364,7 +376,7 @@ export default class DayPickerRangeController extends React.Component {

onDayMouseEnter(day) {
if (this.isTouchDevice) return;
const { startDate, endDate, focusedInput } = this.props;
const { startDate, endDate, focusedInput, minimumNights } = this.props;
const { hoverDate, visibleDays } = this.state;

let modifiers = {};
Expand All @@ -373,11 +385,13 @@ export default class DayPickerRangeController extends React.Component {

if (startDate && !endDate && focusedInput === END_DATE) {
if (isAfterDay(hoverDate, startDate)) {
modifiers = this.deleteModifierFromRange(modifiers, startDate, hoverDate, 'hovered-span');
const endSpan = hoverDate.clone().add(1, 'day');
modifiers = this.deleteModifierFromRange(modifiers, startDate, endSpan, 'hovered-span');
}

if (!this.isBlocked(day) && isAfterDay(day, startDate)) {
modifiers = this.addModifierToRange(modifiers, startDate, day, 'hovered-span');
const endSpan = day.clone().add(1, 'day');
modifiers = this.addModifierToRange(modifiers, startDate, endSpan, 'hovered-span');
}
}

Expand All @@ -391,6 +405,19 @@ export default class DayPickerRangeController extends React.Component {
}
}

if (startDate) {
const startSpan = startDate.clone().add(1, 'day');
const endSpan = startDate.clone().add(minimumNights + 1, 'days');
modifiers = this.deleteModifierFromRange(modifiers, startSpan, endSpan, 'after-hovered-start');

if (isSameDay(day, startDate)) {
const newStartSpan = startDate.clone().add(1, 'day');
const newEndSpan = startDate.clone().add(minimumNights + 1, 'days');
modifiers =
this.addModifierToRange(modifiers, newStartSpan, newEndSpan, 'after-hovered-start');
}
}

this.setState({
hoverDate: day,
visibleDays: {
Expand All @@ -400,22 +427,29 @@ export default class DayPickerRangeController extends React.Component {
});
}

onDayMouseLeave() {
const { startDate, endDate } = this.props;
onDayMouseLeave(day) {
const { startDate, endDate, minimumNights } = this.props;
const { hoverDate, visibleDays } = this.state;
if (this.isTouchDevice || !hoverDate) return;

let modifiers = {};
modifiers = this.deleteModifier(modifiers, hoverDate, 'hovered');

if (startDate && !endDate && isAfterDay(hoverDate, startDate)) {
modifiers = this.deleteModifierFromRange(modifiers, startDate, hoverDate, 'hovered-span');
const endSpan = hoverDate.clone().add(1, 'day');
modifiers = this.deleteModifierFromRange(modifiers, startDate, endSpan, 'hovered-span');
}

if (!startDate && endDate && isAfterDay(endDate, hoverDate)) {
modifiers = this.deleteModifierFromRange(modifiers, hoverDate, endDate, 'hovered-span');
}

if (startDate && isSameDay(day, startDate)) {
const startSpan = startDate.clone().add(1, 'day');
const endSpan = startDate.clone().add(minimumNights + 1, 'days');
modifiers = this.deleteModifierFromRange(modifiers, startSpan, endSpan, 'after-hovered-start');
}

this.setState({
hoverDate: null,
visibleDays: {
Expand Down Expand Up @@ -530,10 +564,10 @@ export default class DayPickerRangeController extends React.Component {
if (!day || !isDayVisible(day, currentMonth, numberOfMonths, enableOutsideDays)) {
return updatedDays;
}

let monthIso = toISOMonthString(day);
let month = updatedDays[monthIso] || visibleDays[monthIso];
const iso = toISODateString(day);

if (enableOutsideDays) {
const startOfMonth = day.clone().startOf('month');
const endOfMonth = day.clone().endOf('month');
Expand All @@ -548,6 +582,7 @@ export default class DayPickerRangeController extends React.Component {
}
}


const modifiers = new Set(month[iso]);
modifiers.add(modifier);
return {
Expand Down
4 changes: 2 additions & 2 deletions stories/DateRangePicker_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const TestCustomCloseIcon = () => (
storiesOf('DRP - Input Props', module)
.addWithInfo('default', () => (
<DateRangePickerWrapper
initialStartDate={moment().add(3, 'days')}
initialEndDate={moment().add(10, 'days')}
initialStartDate={moment().add(3, 'months')}
initialEndDate={moment().add(3, 'months').add(10, 'days')}
/>
))
.addWithInfo('with clear dates button', () => (
Expand Down
Loading