Skip to content
Closed
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
1 change: 1 addition & 0 deletions src/components/input/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

<label class="md-input-placeholder"
[attr.for]="id"
[attr.id]="labelId"
[class.md-empty]="empty"
[class.md-focused]="focused"
[class.md-float]="floatingPlaceholder"
Expand Down
5 changes: 5 additions & 0 deletions src/components/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ describe('MdInput', function () {
fakeAsync(() => {
fixture.detectChanges();

let inputEl = fixture.debugElement.query(By.css('input'));
let el = fixture.debugElement.query(By.css('label'));
expect(el).toBeNull();

Expand All @@ -195,6 +196,10 @@ describe('MdInput', function () {
expect(el).not.toBeNull();
expect(el.nativeElement.textContent).toMatch('Other placeholder');
expect(el.nativeElement.textContent).not.toMatch(/\*/g);

// When placeholder is present, input should be labelled by the label element
expect(inputEl.nativeElement.getAttribute('aria-labelledby')).toBeTruthy();
expect(inputEl.nativeElement.getAttribute('aria-labelledby')).toBe(el.nativeElement.id);
})();
});
});
Expand Down
11 changes: 10 additions & 1 deletion src/components/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,19 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
* Aria related inputs.
*/
@Input('aria-label') ariaLabel: string;
@Input('aria-labelledby') ariaLabelledBy: string;
@Input('aria-disabled') @BooleanFieldValue() ariaDisabled: boolean;
@Input('aria-required') @BooleanFieldValue() ariaRequired: boolean;
@Input('aria-invalid') @BooleanFieldValue() ariaInvalid: boolean;

private _ariaLabelledBy: string;
@Input('aria-labelledby')
get ariaLabelledBy(): string {
return this._ariaLabelledBy || this.labelId || null;
}
set ariaLabelledBy(value: string) {
this._ariaLabelledBy = value;
}

/**
* Content directives.
*/
Expand All @@ -130,6 +138,7 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
return this.empty ? 0 : ('' + this._value).length;
}
get inputId(): string { return `${this.id}-input`; }
get labelId(): string { return `${this.id}-label`; }

/**
* Bindings.
Expand Down