@@ -48,7 +48,14 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
48
48
* @memberof IgxMonthsViewComponent
49
49
*/
50
50
@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
+ }
52
59
53
60
/**
54
61
* Gets the month format option of the months view.
@@ -134,10 +141,11 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
134
141
135
142
136
143
/**
137
- * The default `tabindex` attribute for the component.
144
+ * Gets/sets the `tabindex` attribute for the component.
145
+ * Default value is 0
138
146
*
139
- * @hidden
140
147
*/
148
+ @Input ( )
141
149
@HostBinding ( 'attr.tabindex' )
142
150
public tabindex = 0 ;
143
151
@@ -161,6 +169,13 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
161
169
return result ;
162
170
}
163
171
172
+ /**
173
+ * @hidden
174
+ * @internal
175
+ */
176
+ public activeMonth ;
177
+
178
+ private _date = new Date ( ) ;
164
179
/**
165
180
* @hidden
166
181
*/
@@ -214,6 +229,7 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
214
229
this . onSelection . emit ( event ) ;
215
230
216
231
this . date = event ;
232
+ this . activeMonth = this . date . getMonth ( ) ;
217
233
this . _onChangeCallback ( this . date ) ;
218
234
}
219
235
@@ -274,7 +290,9 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
274
290
const nextNodeRect = months [ index ] . nativeElement . getBoundingClientRect ( ) ;
275
291
const tolerance = 6 ;
276
292
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 ( ) ;
278
296
break ;
279
297
}
280
298
}
@@ -300,7 +318,9 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
300
318
const nextNodeRect = months [ index ] . nativeElement . getBoundingClientRect ( ) ;
301
319
const tolerance = 6 ;
302
320
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 ( ) ;
304
324
break ;
305
325
}
306
326
}
@@ -320,7 +340,7 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
320
340
const months = this . monthsRef . toArray ( ) ;
321
341
if ( months . indexOf ( node ) + 1 < months . length ) {
322
342
const month = months [ months . indexOf ( node ) + 1 ] ;
323
-
343
+ this . activeMonth = month . value . getMonth ( ) ;
324
344
month . nativeElement . focus ( ) ;
325
345
}
326
346
}
@@ -339,7 +359,7 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
339
359
const months = this . monthsRef . toArray ( ) ;
340
360
if ( months . indexOf ( node ) - 1 >= 0 ) {
341
361
const month = months [ months . indexOf ( node ) - 1 ] ;
342
-
362
+ this . activeMonth = month . value . getMonth ( ) ;
343
363
month . nativeElement . focus ( ) ;
344
364
}
345
365
}
@@ -353,7 +373,7 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
353
373
event . stopPropagation ( ) ;
354
374
355
375
const month = this . monthsRef . toArray ( ) [ 0 ] ;
356
-
376
+ this . activeMonth = month . value . getMonth ( ) ;
357
377
month . nativeElement . focus ( ) ;
358
378
}
359
379
@@ -367,7 +387,7 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
367
387
368
388
const months = this . monthsRef . toArray ( ) ;
369
389
const month = months [ months . length - 1 ] ;
370
-
390
+ this . activeMonth = month . value . getMonth ( ) ;
371
391
month . nativeElement . focus ( ) ;
372
392
}
373
393
@@ -378,8 +398,13 @@ export class IgxMonthsViewComponent implements ControlValueAccessor {
378
398
public onKeydownEnter ( event ) {
379
399
const value = this . monthsRef . find ( ( date ) => date . nativeElement === event . target ) . value ;
380
400
this . date = new Date ( value . getFullYear ( ) , value . getMonth ( ) , this . date . getDate ( ) ) ;
381
-
401
+ this . activeMonth = this . date . getMonth ( ) ;
382
402
this . onSelection . emit ( this . date ) ;
383
403
this . _onChangeCallback ( this . date ) ;
384
404
}
405
+
406
+ @HostListener ( 'focusout' , [ '$event' ] )
407
+ public resetActiveMonth ( event ) {
408
+ this . activeMonth = this . date . getMonth ( ) ;
409
+ }
385
410
}
0 commit comments