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): keyboard navigation for accessibility #2270

Merged
merged 1 commit into from
Apr 11, 2018

Conversation

fbasso
Copy link
Member

@fbasso fbasso commented Mar 30, 2018

No description provided.

Copy link
Member

@maxokorokov maxokorokov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR,

Looks good, but a couple of use cases are broken.

Apart from the comments in the code:

  • When focusing left/right navigation arrow → press Enter → it will change the month and move focus to the day. The focus should stay on the arrow. Same for month/year select boxes.

  • I don't think it should be possible to focus a disabled datepicker (it's the case currently, see the demo) + tests for this use case

  • Arrows are not of bootstrap blue color (see comment in the code)

  • active class is broken on a focused day (see comment in the code)

  • Should check the use case when minDate is set and left arrow becomes disabled → it should have tabindex = -1

  • Could you please add Fixes #1716 and BREAKING CHANGES section in the commit? (ex. like here → 2311616). Breaking changes should explain that it's not possible focus the datepicker anymore and .focus() method focuses a day

@@ -68,8 +72,8 @@ import {NgbDatepickerI18n} from './datepicker-i18n';
`],
template: `
<div class="ngb-dp-arrow">
<button type="button" class="btn btn-link ngb-dp-arrow-btn"
(click)="!!navigate.emit(navigation.PREV)" [disabled]="prevDisabled" tabindex="-1">
<button type="button" class="btn ngb-dp-arrow-btn"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The button became black after removing btn-link
I guess we should leave it and override :focus, so it would reflect current bootstrap theme

@@ -132,7 +127,7 @@ export interface NgbDatepickerNavigateEvent {
</ngb-datepicker-navigation>
</div>

<div class="ngb-dp-months">
<div class="ngb-dp-months" (keydown)="onKeyDown($event)" (focus)="showFocus(true)" (focusout)="showFocus(false)">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be (focusin), otherwise showFocus() is never called → we never set focusVisible in the service → we never get active class on the current day (we lost greyish highlight of the current day + day.context.focused is never true)

I also think there are unit tests missing for checking active class on the focused day in datepicker.spec.ts.

focus() { this._elementRef.nativeElement.focus(); }
focus(focusDay = true) {
take.call(this._ngZone.onStable.asObservable(), 1).subscribe(() => {
const elementToFocus = this._elementRef.nativeElement.querySelector(focusDay ? 'div.ngb-dp-day[tabindex="0"]' : 'button');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Focusing button is not an option, because there might be no button whatsoever, ex. with datepicker navigation='none' there are no arrows

I'm actually not sure how we could find what to focus apart from the day... we probably should always focus the day here

Tests missing for this case

@@ -1,4 +1,5 @@
import {Subscription} from 'rxjs/Subscription';
import {take} from 'rxjs/operator/take';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we please change it to and use .pipe in the code?

import {take} from 'rxjs/operators';

It will be merged in 2.0.0 and we're gonna have pipeable operators by default by then

@maxokorokov
Copy link
Member

Oh, also CI failed because of code formatting issue and there is a tiny conflict to resolve

Copy link
Member

@maxokorokov maxokorokov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks a lot!

Could you just remove documentation comment that's not relevant anymore?

@@ -272,8 +275,16 @@ export class NgbDatepicker implements OnDestroy,

/**
* Manually focus the datepicker
* If focusDay is false, the left navigation button will be focused, if true, the focusable day will be focused
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this description, as no longer relevant

BREAKING CHANGE: The datepicker is no longer focusable as a whole component. Instead, the focus is enable on each elements inside the datepicker (navigation buttons, selects, focusable day) in the natural order. The datepicker focus method will focus the focusable day.
@maxokorokov
Copy link
Member

Part of #1946

@maxokorokov maxokorokov merged commit 2daf038 into ng-bootstrap:master Apr 11, 2018
@fbasso fbasso deleted the datepicker_PR branch April 12, 2018 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants