Skip to content

Commit d7410a8

Browse files
author
Nima Izadi
authored
Merge pull request #601 from Shopify/fix_datepicker_references_date
[DatePicker] Fix date comparision when different references
2 parents f9ef5bd + 56198df commit d7410a8

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

UNRELEASED.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
88

99
### Bug fixes
1010

11+
- Fixed `Datepicker` ranges when `start` and `end` dates are similar but have different references ([#601](https://github.com/Shopify/polaris-react/pull/601))
1112
- Fixed `DataTable` fixed column in production enviroments by using a data-attribute target instead of class based targeting ([#615](https://github.com/Shopify/polaris-react/pull/615))
1213
- Fixed `Navigation.Item` not calling `onClick` on small screens when `onNavigationDismiss` is undefined ([#603](https://github.com/Shopify/polaris-react/pull/603))
1314
- Fixed `Autocomplete` empty state example Markdown not parsing correctly ([#592](https://github.com/Shopify/polaris-react/pull/592))

src/components/DatePicker/components/Month/Month.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function hoveringDateIsInRange(
142142
return false;
143143
}
144144
const {start, end} = range;
145-
return Boolean(start === end && day > start && day <= hoverEndDate);
145+
return Boolean(isSameDay(start, end) && day > start && day <= hoverEndDate);
146146
}
147147

148148
function getWeekdaysOrdered(weekStartsOn: Weekdays): Weekdays[] {

src/components/DatePicker/components/Month/tests/Month.test.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Weekdays} from '@shopify/javascript-utilities/dates';
33
import {mountWithAppProvider} from 'test-utilities';
44
import {Weekday} from '../..';
55
import Month from '../Month';
6+
import Day from '../../Day';
67

78
describe('<Month />', () => {
89
describe('title', () => {
@@ -66,4 +67,26 @@ describe('<Month />', () => {
6667
).toBe(false);
6768
});
6869
});
70+
71+
describe('with allowRange prop to true', () => {
72+
it('range can be created even if start and end have different references', () => {
73+
const hoverDate = new Date('05 Jan 2018 00:00:00 GMT');
74+
const month = mountWithAppProvider(
75+
<Month
76+
month={0}
77+
year={2018}
78+
weekStartsOn={Weekdays.Monday}
79+
allowRange
80+
hoverDate={hoverDate}
81+
selected={{
82+
start: new Date('01 Jan 2018 00:00:00 GMT'),
83+
end: new Date('01 Jan 2018 00:00:00 GMT'),
84+
}}
85+
/>,
86+
);
87+
88+
expect(month.find(Day).get(2).props.inHoveringRange).toBeTruthy();
89+
expect(month.find(Day).get(10).props.inHoveringRange).toBeFalsy();
90+
});
91+
});
6992
});

0 commit comments

Comments
 (0)