Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/lib/datepicker/datepicker-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ export const MD_DATEPICKER_VALIDATORS: any = {
selector: 'input[mdDatepicker], input[matDatepicker]',
providers: [MD_DATEPICKER_VALUE_ACCESSOR, MD_DATEPICKER_VALIDATORS],
host: {
'[attr.aria-expanded]': '_datepicker?.opened || "false"',
'[attr.aria-haspopup]': 'true',
'[attr.aria-owns]': '_datepicker?.id',
'[attr.aria-owns]': '(_datepicker?.opened && _datepicker.id) || null',
'[attr.min]': 'min ? _dateAdapter.getISODateString(min) : null',
'[attr.max]': 'max ? _dateAdapter.getISODateString(max) : null',
'[disabled]': 'disabled',
Expand Down
33 changes: 33 additions & 0 deletions src/lib/datepicker/datepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,39 @@ describe('MdDatepicker', () => {
expect(attachToRef.nativeElement.tagName.toLowerCase())
.toBe('input', 'popup should be attached to native input');
});

it('input should aria-owns calendar after opened in non-touch mode', () => {
let inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
expect(inputEl.getAttribute('aria-owns')).toBeNull();

testComponent.datepicker.open();
fixture.detectChanges();

let ownedElementId = inputEl.getAttribute('aria-owns');
expect(ownedElementId).not.toBeNull();

let ownedElement = document.getElementById(ownedElementId);
expect(ownedElement).not.toBeNull();
expect((ownedElement as Element).tagName.toLowerCase()).toBe('md-calendar');
});

it('input should aria-owns calendar after opened in touch mode', () => {
testComponent.touch = true;
fixture.detectChanges();

let inputEl = fixture.debugElement.query(By.css('input')).nativeElement;
expect(inputEl.getAttribute('aria-owns')).toBeNull();

testComponent.datepicker.open();
fixture.detectChanges();

let ownedElementId = inputEl.getAttribute('aria-owns');
expect(ownedElementId).not.toBeNull();

let ownedElement = document.getElementById(ownedElementId);
expect(ownedElement).not.toBeNull();
expect((ownedElement as Element).tagName.toLowerCase()).toBe('md-calendar');
});
});

describe('datepicker with too many inputs', () => {
Expand Down