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

fix(datepicker): set role on datepicker popup and aria-haspopup on the datepicker toggle #12008

Merged
merged 1 commit into from Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/lib/datepicker/datepicker-toggle.html
@@ -1,5 +1,10 @@
<button mat-icon-button type="button" [attr.aria-label]="_intl.openCalendarLabel"
[disabled]="disabled" (click)="_open($event)">
<button
mat-icon-button
type="button"
aria-haspopup="true"
[attr.aria-label]="_intl.openCalendarLabel"
[disabled]="disabled"
(click)="_open($event)">

<svg
*ngIf="!_customIcon"
Expand Down
7 changes: 4 additions & 3 deletions src/lib/datepicker/datepicker.md
Expand Up @@ -65,7 +65,7 @@ set to something like `new Date(2017, MM, dd)` when the calendar was opened (the
irrelevant in this case).

Notice that the emitted value does not affect the current value in the connected `<input>`, which
is only bound to the selection made in the `month` view. So if the end user closes the calendar
is only bound to the selection made in the `month` view. So if the end user closes the calendar
after choosing a year in `multi-view` mode (by pressing the `ESC` key, for example), the selected
year, emitted by `yearSelected` output, will not cause any change in the value of the date in the
associated `<input>`.
Expand Down Expand Up @@ -330,8 +330,9 @@ export class MyApp {}

### Accessibility

The `MatDatepickerInput` directive adds `aria-haspopup` attribute to the native input element, and it
triggers a calendar dialog with `role="dialog"`.
The `MatDatepickerInput` and `MatDatepickerToggle` directives add the `aria-haspopup` attribute to
the native input and toggle button elements respectively, and they trigger a calendar dialog with
`role="dialog"`.

`MatDatepickerIntl` includes strings that are used for `aria-label`s. The datepicker input
should have a placeholder or be given a meaningful label via `aria-label`, `aria-labelledby` or
Expand Down
17 changes: 17 additions & 0 deletions src/lib/datepicker/datepicker.spec.ts
Expand Up @@ -185,6 +185,16 @@ describe('MatDatepicker', () => {
expect(testComponent.datepicker.opened).toBe(false, 'Expected datepicker to be closed.');
}));

it('should set the proper role on the popup', fakeAsync(() => {
testComponent.datepicker.open();
fixture.detectChanges();
flush();

const popup = document.querySelector('.cdk-overlay-pane')!;
expect(popup).toBeTruthy();
expect(popup.getAttribute('role')).toBe('dialog');
}));

it('close should close dialog', fakeAsync(() => {
testComponent.touch = true;
fixture.detectChanges();
Expand Down Expand Up @@ -800,6 +810,13 @@ describe('MatDatepicker', () => {
flush();
}));

it('should set `aria-haspopup` on the toggle button', () => {
const button = fixture.debugElement.query(By.css('button'));

expect(button).toBeTruthy();
expect(button.nativeElement.getAttribute('aria-haspopup')).toBe('true');
});

it('should open calendar when toggle clicked', () => {
expect(document.querySelector('mat-dialog-container')).toBeNull();

Expand Down
1 change: 1 addition & 0 deletions src/lib/datepicker/datepicker.ts
Expand Up @@ -426,6 +426,7 @@ export class MatDatepicker<D> implements OnDestroy, CanColor {
});

this._popupRef = this._overlay.create(overlayConfig);
this._popupRef.overlayElement.setAttribute('role', 'dialog');

merge(
this._popupRef.backdropClick(),
Expand Down