-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(datepicker): add keyboard support to calendar #3655
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly nits. I did play with the demo, and I was wondering about the focus of the datepicker overlay. When I open the overlay with the keyboard, the focus doesn't seem to be on the overlay, so I have to hit TAB a few more times to get to the calendar body. At first, it doesn't seem like it's keyboard navigable for this reason. Can we explicitly focus the panel when it opens to make this more obvious?
src/lib/datepicker/calendar.ts
Outdated
/** | ||
* Adds the given number of months to the date. Months are counted as if flipping 12 pages for | ||
* each year on a calendar and then finding the closest date in the new month. For example when | ||
* adding 1 year to Feb 29 2016 the resulting date will be Feb 28 2017. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ultra nit: add comma after 'Feb 29, 2016' (same for line 241)? Love the detailed comment though
src/lib/datepicker/calendar.ts
Outdated
* Jan 31 2017 the resulting date will be Feb 28 2017. | ||
*/ | ||
private _addCalendarMonths(date: SimpleDate, months: number): SimpleDate { | ||
let newDate = date.add({'months': months}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can shorten this to
let newDate = date.add({months})
(same on line 235)
return this._monthView ? | ||
date1.year == date2.year && date1.month == date2.month : | ||
date1.year == date2.year; | ||
} | ||
|
||
/** Handles keydown events on the calendar body. */ | ||
_handleCalendarBodyKeydown(event: KeyboardEvent): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considered breaking this logic out into its own mini-service?
Also, have you thought about separating into two functions -one for month view and one for year view? Not sure if that will actually shorten anything, but it may be easier to scan it without the conditionals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what we'd gain by making it a service, I split out 2 separate functions for month view and year view though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just thought the file was getting pretty long, but if you don't think so, doesn't matter too much.
|
||
it('should not allow selection of disabled date in month view', () => { | ||
expect(calendarInstance._monthView).toBe(true); | ||
expect(calendarInstance._activeDate).toEqual(new SimpleDate(2017, 0, 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious about this behavior. It seems like we allow people to focus the disabled dates, but not select them, whereas AngularJS Material doesn't allow highlighting of disabled dates at all. What's the a11y best practice for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this was more of a practical decision, since someone could theoretically create a calendar with no maxDate but a date filter that disables all dates > 1/1/17. In this case if the user tried to arrow past 1/1/17 everything would just lock up as it searched for the next enabled date. I put a TODO and I'm curious to see how AngularJS Material handled this
src/lib/datepicker/calendar.spec.ts
Outdated
}); | ||
}); | ||
|
||
describe('a11y', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Two describe blocks both named a11y
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of them is MdCalendar.calendar with date filter.a11y
the other is MdCalendar.a11y
(though it should be MdCalendar.standard calendar.a11y
so making that change).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha I see. The diff was a bit misleading.
Yeah focus state when you open the calendar is still kind of wonky, I'll address that in a different PR. Addressed other comments, PTAL. |
src/lib/datepicker/calendar.ts
Outdated
/** | ||
* Adds the given number of months to the date. Months are counted as if flipping pages on a | ||
* calendar and then finding the closest date in the new month. For example when adding 1 month to | ||
* Jan 31, 2017 the resulting date will be Feb 28, 2017. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, sorry for being unclear. I meant a comma after "2017", not in the date.
For example, when adding 1 month to Jan 31, 2017, the resulting date will be ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Apply merge label when ready.
* add active cell support to calendar-table, month-view, and year-view * stop normalizing the active date in calendar since we now care about the exact active date * add some key handlers * add keyboard support, break some tests * add tests * some finishing touches * fix tabindex * fix rxjs import * addressed some comments * refactor handleKeydown * fix commas
* add active cell support to calendar-table, month-view, and year-view * stop normalizing the active date in calendar since we now care about the exact active date * add some key handlers * add keyboard support, break some tests * add tests * some finishing touches * fix tabindex * fix rxjs import * addressed some comments * refactor handleKeydown * fix commas
* add active cell support to calendar-table, month-view, and year-view * stop normalizing the active date in calendar since we now care about the exact active date * add some key handlers * add keyboard support, break some tests * add tests * some finishing touches * fix tabindex * fix rxjs import * addressed some comments * refactor handleKeydown * fix commas
* add active cell support to calendar-table, month-view, and year-view * stop normalizing the active date in calendar since we now care about the exact active date * add some key handlers * add keyboard support, break some tests * add tests * some finishing touches * fix tabindex * fix rxjs import * addressed some comments * refactor handleKeydown * fix commas
* add active cell support to calendar-table, month-view, and year-view * stop normalizing the active date in calendar since we now care about the exact active date * add some key handlers * add keyboard support, break some tests * add tests * some finishing touches * fix tabindex * fix rxjs import * addressed some comments * refactor handleKeydown * fix commas
* add active cell support to calendar-table, month-view, and year-view * stop normalizing the active date in calendar since we now care about the exact active date * add some key handlers * add keyboard support, break some tests * add tests * some finishing touches * fix tabindex * fix rxjs import * addressed some comments * refactor handleKeydown * fix commas
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
temporary demo: https://mmalerba-demo1.firebaseapp.com/datepicker