@@ -48,7 +48,14 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
4848 * @memberof IgxMonthsViewComponent
4949 */
5050 @Input ( )
51- public date = new Date ( ) ;
51+ public set date ( value ) {
52+ this . _date = value ;
53+ this . activeMonth = this . date . getMonth ( ) ;
54+ }
55+
56+ public get date ( ) {
57+ return this . _date ;
58+ }
5259
5360 /**
5461 * Gets the month format option of the months view.
@@ -134,10 +141,11 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
134141
135142
136143 /**
137- * The default `tabindex` attribute for the component.
144+ * Gets/sets the `tabindex` attribute for the component.
145+ * Default value is 0
138146 *
139- * @hidden
140147 */
148+ @Input ( )
141149 @HostBinding ( 'attr.tabindex' )
142150 public tabindex = 0 ;
143151
@@ -161,6 +169,13 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
161169 return result ;
162170 }
163171
172+ /**
173+ * @hidden
174+ * @internal
175+ */
176+ public activeMonth ;
177+
178+ private _date = new Date ( ) ;
164179 /**
165180 * @hidden
166181 */
@@ -214,6 +229,7 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
214229 this . onSelection . emit ( event ) ;
215230
216231 this . date = event ;
232+ this . activeMonth = this . date . getMonth ( ) ;
217233 this . _onChangeCallback ( this . date ) ;
218234 }
219235
@@ -274,7 +290,9 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
274290 const nextNodeRect = months [ index ] . nativeElement . getBoundingClientRect ( ) ;
275291 const tolerance = 6 ;
276292 if ( nodeRect . top !== nextNodeRect . top && ( nextNodeRect . left - nodeRect . left ) < tolerance ) {
277- months [ index ] . nativeElement . focus ( ) ;
293+ const month = months [ index ] ;
294+ month . nativeElement . focus ( ) ;
295+ this . activeMonth = month . value . getMonth ( ) ;
278296 break ;
279297 }
280298 }
@@ -300,7 +318,9 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
300318 const nextNodeRect = months [ index ] . nativeElement . getBoundingClientRect ( ) ;
301319 const tolerance = 6 ;
302320 if ( nextNodeRect . top !== nodeRect . top && ( nodeRect . left - nextNodeRect . left ) < tolerance ) {
303- months [ index ] . nativeElement . focus ( ) ;
321+ const month = months [ index ] ;
322+ month . nativeElement . focus ( ) ;
323+ this . activeMonth = month . value . getMonth ( ) ;
304324 break ;
305325 }
306326 }
@@ -320,7 +340,7 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
320340 const months = this . monthsRef . toArray ( ) ;
321341 if ( months . indexOf ( node ) + 1 < months . length ) {
322342 const month = months [ months . indexOf ( node ) + 1 ] ;
323-
343+ this . activeMonth = month . value . getMonth ( ) ;
324344 month . nativeElement . focus ( ) ;
325345 }
326346 }
@@ -339,7 +359,7 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
339359 const months = this . monthsRef . toArray ( ) ;
340360 if ( months . indexOf ( node ) - 1 >= 0 ) {
341361 const month = months [ months . indexOf ( node ) - 1 ] ;
342-
362+ this . activeMonth = month . value . getMonth ( ) ;
343363 month . nativeElement . focus ( ) ;
344364 }
345365 }
@@ -353,7 +373,7 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
353373 event . stopPropagation ( ) ;
354374
355375 const month = this . monthsRef . toArray ( ) [ 0 ] ;
356-
376+ this . activeMonth = month . value . getMonth ( ) ;
357377 month . nativeElement . focus ( ) ;
358378 }
359379
@@ -367,7 +387,7 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
367387
368388 const months = this . monthsRef . toArray ( ) ;
369389 const month = months [ months . length - 1 ] ;
370-
390+ this . activeMonth = month . value . getMonth ( ) ;
371391 month . nativeElement . focus ( ) ;
372392 }
373393
@@ -378,8 +398,13 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
378398 public onKeydownEnter ( event ) {
379399 const value = this . monthsRef . find ( ( date ) => date . nativeElement === event . target ) . value ;
380400 this . date = new Date ( value . getFullYear ( ) , value . getMonth ( ) , this . date . getDate ( ) ) ;
381-
401+ this . activeMonth = this . date . getMonth ( ) ;
382402 this . onSelection . emit ( this . date ) ;
383403 this . _onChangeCallback ( this . date ) ;
384404 }
405+
406+ @HostListener ( 'focusout' , [ '$event' ] )
407+ public resetActiveMonth ( event ) {
408+ this . activeMonth = this . date . getMonth ( ) ;
409+ }
385410}
0 commit comments