@@ -628,7 +628,11 @@ export class UIUpdaterService {
628628 monthsContainer . classList . add ( 'date-picker-months-grid' ) ;
629629 monthsContainer . setAttribute ( 'role' , 'grid' ) ;
630630
631- // Create months grid (3x4)
631+ // Current date for highlighting today's month if in current year
632+ const today = new Date ( ) ;
633+ const isCurrentYear = today . getFullYear ( ) === year ;
634+
635+ // Create months grid (4x3)
632636 for ( let row = 0 ; row < 4 ; row ++ ) {
633637 const monthRow = document . createElement ( 'div' ) ;
634638 monthRow . classList . add ( 'date-picker-row' ) ;
@@ -639,8 +643,14 @@ export class UIUpdaterService {
639643 const monthElement = document . createElement ( 'div' ) ;
640644 monthElement . classList . add ( 'date-picker-cell' , 'month-cell' ) ;
641645 monthElement . setAttribute ( 'role' , 'gridcell' ) ;
646+ monthElement . setAttribute ( 'data-month' , monthIndex . toString ( ) ) ;
647+
648+ // Only add selected class if we're looking at the current month in the current view
649+ // This is the key fix: Only highlight the month if it's the selected month AND in the current year
650+ const currentDate = new Date ( ) ;
651+ currentDate . setFullYear ( year ) ;
652+ currentDate . setMonth ( monthIndex ) ;
642653
643- // Check if month is selected
644654 if ( monthIndex === currentMonth ) {
645655 monthElement . classList . add ( 'selected' ) ;
646656 monthElement . setAttribute ( 'tabindex' , '0' ) ;
@@ -649,8 +659,7 @@ export class UIUpdaterService {
649659 }
650660
651661 // Check if it's current month in current year
652- const today = new Date ( ) ;
653- if ( today . getMonth ( ) === monthIndex && today . getFullYear ( ) === year ) {
662+ if ( isCurrentYear && today . getMonth ( ) === monthIndex ) {
654663 monthElement . classList . add ( 'current' ) ;
655664 }
656665
@@ -687,8 +696,8 @@ export class UIUpdaterService {
687696 yearsContainer . classList . add ( 'date-picker-years-grid' ) ;
688697 yearsContainer . setAttribute ( 'role' , 'grid' ) ;
689698
690- // Track if the selected year is in the displayed range
691- let selectedYearVisible = false ;
699+ // Only highlight the year if it's within the current view range
700+ const shouldHighlight = currentYear >= startYear && currentYear <= endYear ;
692701
693702 // Create years grid (4x3)
694703 let yearIndex = startYear ;
@@ -703,13 +712,14 @@ export class UIUpdaterService {
703712 const yearElement = document . createElement ( 'div' ) ;
704713 yearElement . classList . add ( 'date-picker-cell' , 'year-cell' ) ;
705714 yearElement . setAttribute ( 'role' , 'gridcell' ) ;
715+ yearElement . setAttribute ( 'data-year' , yearIndex . toString ( ) ) ;
716+
717+ // Only highlight if the year is in the current view range
718+ const isSelected = shouldHighlight && ( yearIndex === currentYear ) ;
706719
707- // Check if year is selected
708- const isSelected = yearIndex === currentYear ;
709720 if ( isSelected ) {
710721 yearElement . classList . add ( 'selected' ) ;
711722 yearElement . setAttribute ( 'tabindex' , '0' ) ;
712- selectedYearVisible = true ;
713723 } else {
714724 yearElement . setAttribute ( 'tabindex' , '-1' ) ;
715725 }
@@ -729,8 +739,6 @@ export class UIUpdaterService {
729739 // Prevent the event from bubbling up which might cause the calendar to close
730740 e . stopPropagation ( ) ;
731741 e . preventDefault ( ) ;
732- // Log which year was selected for debugging
733- console . log ( `Year selected: ${ actualYear } ` ) ;
734742 onSelectYear ( actualYear ) ;
735743 } ) ;
736744
0 commit comments