From 40d65ba62b95b75ce456b3195d1f8fba207e651e Mon Sep 17 00:00:00 2001 From: SAndreeva Date: Wed, 13 Feb 2019 15:11:48 +0200 Subject: [PATCH] feat(month picker): add KB to month picker component #3126 --- .../src/lib/calendar/README.md | 2 +- .../month-picker/month-picker.component.html | 8 ++-- .../month-picker/month-picker.component.ts | 39 ++++++++++++++++++- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/projects/igniteui-angular/src/lib/calendar/README.md b/projects/igniteui-angular/src/lib/calendar/README.md index 3789b156f85..83b18711873 100644 --- a/projects/igniteui-angular/src/lib/calendar/README.md +++ b/projects/igniteui-angular/src/lib/calendar/README.md @@ -70,7 +70,7 @@ When the **igxCalendar** component is focused: - `Tab` will navigate through the subheader buttons; When `prev` or `next` month buttons (in the subheader) are focused: -- `Space` will scroll into view the next or previous month. +- `Space` or `Enter` will scroll into view the next or previous month. When `months` button (in the subheader) is focused: - `Space` or `Enter` will open the months view. diff --git a/projects/igniteui-angular/src/lib/month-picker/month-picker.component.html b/projects/igniteui-angular/src/lib/month-picker/month-picker.component.html index 3713d4e58f6..be9ccd2c6fe 100644 --- a/projects/igniteui-angular/src/lib/month-picker/month-picker.component.html +++ b/projects/igniteui-angular/src/lib/month-picker/month-picker.component.html @@ -1,14 +1,14 @@ -
+
-
+
keyboard_arrow_left
- + {{ formattedYear(viewDate) }}
-
+
keyboard_arrow_right
diff --git a/projects/igniteui-angular/src/lib/month-picker/month-picker.component.ts b/projects/igniteui-angular/src/lib/month-picker/month-picker.component.ts index d5c1ef8a8fb..a1c25f02970 100644 --- a/projects/igniteui-angular/src/lib/month-picker/month-picker.component.ts +++ b/projects/igniteui-angular/src/lib/month-picker/month-picker.component.ts @@ -1,7 +1,9 @@ import { Component, NgModule, - HostListener + HostListener, + ElementRef, + ViewChild } from '@angular/core'; import { IgxCalendarModule, CalendarView, IgxCalendarComponent } from '../calendar/index'; import { IgxIconModule } from '../icon/index'; @@ -9,6 +11,7 @@ import { NG_VALUE_ACCESSOR } from '@angular/forms'; import { CommonModule } from '@angular/common'; import { trigger, transition, useAnimation } from '@angular/animations'; import { fadeIn, scaleInCenter, slideInLeft, slideInRight } from '../animations/main'; +import { KEYS } from '../core/utils'; @Component({ providers: [ @@ -51,6 +54,12 @@ export class IgxMonthPickerComponent extends IgxCalendarComponent { */ public yearAction = ''; + /** + * @hidden + */ + @ViewChild('yearsBtn') + public yearsBtn: ElementRef; + /** * @hidden */ @@ -66,6 +75,18 @@ export class IgxMonthPickerComponent extends IgxCalendarComponent { super.nextYear(); } + /** + * @hidden + */ + public nextYearKB(event) { + if (event.key === KEYS.SPACE || event.key === KEYS.SPACE_IE || event.key === KEYS.ENTER) { + event.preventDefault(); + event.stopPropagation(); + + this.nextYear(); + } + } + /** * @hidden */ @@ -74,6 +95,18 @@ export class IgxMonthPickerComponent extends IgxCalendarComponent { super.previousYear(); } + /** + * @hidden + */ + public previousYearKB(event) { + if (event.key === KEYS.SPACE || event.key === KEYS.SPACE_IE || event.key === KEYS.ENTER) { + event.preventDefault(); + event.stopPropagation(); + + this.previousYear(); + } + } + /** * @hidden */ @@ -90,6 +123,10 @@ export class IgxMonthPickerComponent extends IgxCalendarComponent { public selectYear(event: Date) { this.viewDate = new Date(event.getFullYear(), event.getMonth(), event.getDate()); this.activeView = CalendarView.DEFAULT; + + requestAnimationFrame(() => { + this.yearsBtn.nativeElement.focus(); + }); } /**