File tree Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Expand file tree Collapse file tree 3 files changed +45
-2
lines changed Original file line number Diff line number Diff line change @@ -122,7 +122,10 @@ class Calendar extends PureComponent {
122122 date : 'date' ,
123123 } ;
124124 const targetProp = propMapper [ this . props . displayMode ] ;
125- if ( this . props [ targetProp ] !== prevProps [ targetProp ] ) {
125+ if (
126+ this . props [ targetProp ] !== prevProps [ targetProp ] ||
127+ this . props . focusedRange != prevProps . focusedRange
128+ ) {
126129 this . updateShownDate ( this . props ) ;
127130 }
128131
Original file line number Diff line number Diff line change @@ -27,7 +27,12 @@ export function calcFocusDate(currentFocusedDate, props) {
2727 }
2828 targetInterval . start = startOfMonth ( targetInterval . start || new Date ( ) ) ;
2929 targetInterval . end = endOfMonth ( targetInterval . end || targetInterval . start ) ;
30- const targetDate = targetInterval . start || targetInterval . end || shownDate || new Date ( ) ;
30+ const targetDate =
31+ ( focusedRange [ 1 ]
32+ ? targetInterval . end || targetInterval . start
33+ : targetInterval . start || targetInterval . end ) ||
34+ shownDate ||
35+ new Date ( ) ;
3136
3237 // initial focus
3338 if ( ! currentFocusedDate ) return shownDate || targetDate ;
Original file line number Diff line number Diff line change 1+ import { endOfMonth , startOfMonth } from 'date-fns' ;
2+ import { calcFocusDate } from './utils' ;
3+
4+ describe ( 'calcFocusDate' , ( ) => {
5+ const ranges = [
6+ {
7+ startDate : new Date ( 2021 , 0 , 10 ) ,
8+ endDate : new Date ( 2022 , 10 , 20 ) ,
9+ } ,
10+ ] ;
11+
12+ describe ( 'when focusedRange[1] equals 0' , ( ) => {
13+ test ( 'should return startDate' , ( ) => {
14+ expect (
15+ calcFocusDate ( new Date ( ) , {
16+ ranges,
17+ focusedRange : [ 0 , 0 ] ,
18+ displayMode : 'dateRange' ,
19+ } )
20+ ) . toEqual ( startOfMonth ( ranges [ 0 ] . startDate ) ) ;
21+ } ) ;
22+ } ) ;
23+
24+ describe ( 'when focusedRange[1] equals 1' , ( ) => {
25+ test ( 'should return endDate' , ( ) => {
26+ expect (
27+ calcFocusDate ( new Date ( ) , {
28+ ranges,
29+ focusedRange : [ 0 , 1 ] ,
30+ displayMode : 'dateRange' ,
31+ } )
32+ ) . toEqual ( endOfMonth ( ranges [ 0 ] . endDate ) ) ;
33+ } ) ;
34+ } ) ;
35+ } ) ;
You can’t perform that action at this time.
0 commit comments