Skip to content
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

Merged
merged 11 commits into from
Mar 24, 2017

Conversation

mmalerba
Copy link
Contributor

@mmalerba mmalerba commented Mar 17, 2017

@mmalerba mmalerba requested review from jelbourn and kara March 17, 2017 16:12
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Mar 17, 2017
Copy link
Contributor

@kara kara left a 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?

/**
* 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.
Copy link
Contributor

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

* Jan 31 2017 the resulting date will be Feb 28 2017.
*/
private _addCalendarMonths(date: SimpleDate, months: number): SimpleDate {
let newDate = date.add({'months': months});
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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));
Copy link
Contributor

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?

Copy link
Contributor Author

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

});
});

describe('a11y', () => {
Copy link
Contributor

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?

Copy link
Contributor Author

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).

Copy link
Contributor

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.

@kara kara unassigned jelbourn and kara Mar 23, 2017
@mmalerba
Copy link
Contributor Author

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.

/**
* 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.
Copy link
Contributor

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 ...

Copy link
Contributor

@kara kara left a 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.

@mmalerba mmalerba merged commit 5170bed into angular:datepicker Mar 24, 2017
mmalerba added a commit to mmalerba/components that referenced this pull request Mar 28, 2017
* 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
mmalerba added a commit that referenced this pull request Apr 14, 2017
* 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
mmalerba added a commit that referenced this pull request Apr 20, 2017
* 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
mmalerba added a commit that referenced this pull request Apr 29, 2017
* 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
mmalerba added a commit that referenced this pull request May 5, 2017
* 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
mmalerba added a commit that referenced this pull request May 9, 2017
* 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
@mmalerba mmalerba deleted the dp branch April 3, 2018 15:16
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants