@@ -421,6 +421,8 @@ class Calendar extends UI5Element {
421
421
_handleSelectedDatesChange ( event ) {
422
422
this . selectedDates = [ ...event . detail . dates ] ;
423
423
424
+ this . timestamp = this . selectedDates [ 0 ] ;
425
+
424
426
this . fireEvent ( "selected-dates-change" , { dates : event . detail . dates } ) ;
425
427
}
426
428
@@ -438,21 +440,6 @@ class Calendar extends UI5Element {
438
440
}
439
441
}
440
442
441
- _handleSelectedMonthChange ( event ) {
442
- const oNewDate = this . _calendarDate ;
443
- const newMonthIndex = CalendarDate . fromTimestamp (
444
- event . detail . timestamp * 1000 ,
445
- this . _primaryCalendarType
446
- ) . getMonth ( ) ;
447
-
448
- oNewDate . setMonth ( newMonthIndex ) ;
449
- this . timestamp = oNewDate . valueOf ( ) / 1000 ;
450
-
451
- this . _hideMonthPicker ( ) ;
452
-
453
- this . _focusFirstDayOfMonth ( oNewDate ) ;
454
- }
455
-
456
443
_focusFirstDayOfMonth ( targetDate ) {
457
444
let fistDayOfMonthIndex = - 1 ;
458
445
@@ -469,19 +456,35 @@ class Calendar extends UI5Element {
469
456
dayPicker . _itemNav . focusCurrent ( ) ;
470
457
}
471
458
459
+ _handleSelectedMonthChange ( event ) {
460
+ const oNewDate = this . _calendarDate ;
461
+ const oFocusedDate = CalendarDate . fromTimestamp ( event . detail . timestamp * 1000 , this . _primaryCalendarType ) ;
462
+
463
+ oNewDate . setMonth ( oFocusedDate . getMonth ( ) ) ;
464
+ this . timestamp = oNewDate . valueOf ( ) / 1000 ;
465
+ this . _monthPicker . timestamp = this . timestamp ;
466
+
467
+ this . _hideMonthPicker ( ) ;
468
+ this . _setDayPickerCurrentIndex ( oNewDate ) ;
469
+ }
470
+
472
471
_handleSelectedYearChange ( event ) {
473
- const oNewDate = CalendarDate . fromTimestamp (
474
- event . detail . timestamp * 1000 ,
475
- this . _primaryCalendarType
476
- ) ;
477
- oNewDate . setMonth ( 0 ) ;
478
- oNewDate . setDate ( 1 ) ;
472
+ const oNewDate = this . _calendarDate ;
473
+ const oFocusedDate = CalendarDate . fromTimestamp ( event . detail . timestamp * 1000 , this . _primaryCalendarType ) ;
479
474
475
+ oNewDate . setYear ( oFocusedDate . getYear ( ) ) ;
480
476
this . timestamp = oNewDate . valueOf ( ) / 1000 ;
477
+ this . _yearPicker . timestamp = this . timestamp ;
481
478
482
479
this . _hideYearPicker ( ) ;
480
+ this . _setDayPickerCurrentIndex ( oNewDate ) ;
481
+ }
483
482
484
- this . _focusFirstDayOfMonth ( oNewDate ) ;
483
+ _setDayPickerCurrentIndex ( calDate ) {
484
+ const currentDate = new CalendarDate ( calDate ) ;
485
+ const dayPicker = this . shadowRoot . querySelector ( "[ui5-daypicker]" ) ;
486
+ const currentDateIndex = dayPicker . _getVisibleDays ( currentDate ) . findIndex ( date => date . valueOf ( ) === currentDate . valueOf ( ) ) ;
487
+ dayPicker . _itemNav . currentIndex = currentDateIndex ;
485
488
}
486
489
487
490
_handleMonthButtonPress ( ) {
@@ -565,11 +568,9 @@ class Calendar extends UI5Element {
565
568
}
566
569
} ) ;
567
570
568
- const weekDaysCount = 7 ;
569
-
570
571
if ( lastDayOfMonthIndex !== - 1 ) {
571
572
// find the DOM for the last day index
572
- const lastDay = dayPicker . shadowRoot . querySelector ( ".ui5-dp-content" ) . children [ parseInt ( lastDayOfMonthIndex / weekDaysCount ) + 1 ] . children [ ( lastDayOfMonthIndex % weekDaysCount ) ] ;
573
+ const lastDay = dayPicker . shadowRoot . querySelectorAll ( ".ui5-dp-content .ui5-dp-item" ) [ lastDayOfMonthIndex ] ;
573
574
574
575
// update current item in ItemNavigation
575
576
dayPicker . _itemNav . current = lastDayOfMonthIndex ;
@@ -675,6 +676,14 @@ class Calendar extends UI5Element {
675
676
676
677
this . _calendarWidth = calendarRect . width . toString ( ) ;
677
678
this . _calendarHeight = calendarRect . height . toString ( ) ;
679
+
680
+ const monthPicker = this . shadowRoot . querySelector ( "[ui5-monthpicker]" ) ;
681
+ monthPicker . _selectedDates = [ ...this . selectedDates ] ;
682
+ const currentMonthIndex = monthPicker . _itemNav . _getItems ( ) . findIndex ( item => {
683
+ const calDate = CalendarDate . fromTimestamp ( parseInt ( item . timestamp ) * 1000 , this . _primaryCalendarType ) ;
684
+ return calDate . getMonth ( ) === this . _calendarDate . getMonth ( ) ;
685
+ } ) ;
686
+ monthPicker . _itemNav . currentIndex = currentMonthIndex ;
678
687
this . _header . _isMonthButtonHidden = true ;
679
688
}
680
689
@@ -691,6 +700,14 @@ class Calendar extends UI5Element {
691
700
692
701
this . _calendarWidth = calendarRect . width . toString ( ) ;
693
702
this . _calendarHeight = calendarRect . height . toString ( ) ;
703
+
704
+ const yearPicker = this . shadowRoot . querySelector ( "[ui5-yearpicker]" ) ;
705
+ yearPicker . _selectedDates = [ ...this . selectedDates ] ;
706
+ const currentYearIndex = yearPicker . _itemNav . _getItems ( ) . findIndex ( item => {
707
+ const calDate = CalendarDate . fromTimestamp ( parseInt ( item . timestamp ) * 1000 , this . _primaryCalendarType ) ;
708
+ return calDate . getYear ( ) === this . _calendarDate . getYear ( ) ;
709
+ } ) ;
710
+ yearPicker . _itemNav . currentIndex = currentYearIndex ;
694
711
}
695
712
696
713
_hideMonthPicker ( ) {
0 commit comments