Skip to content

Commit

Permalink
fix(input): input element should have a different id from outer eleme…
Browse files Browse the repository at this point in the history
…nt (#450)

closes #320
  • Loading branch information
robertmesserle authored and jelbourn committed May 16, 2016
1 parent 33a88ac commit be5e93a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/input/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[attr.aria-disabled]="ariaDisabled"
[attr.aria-required]="ariaRequired"
[attr.aria-invalid]="ariaInvalid"
[id]="id"
[id]="inputId"
[disabled]="disabled"
[required]="required"
[spellcheck]="spellcheck"
Expand Down
20 changes: 20 additions & 0 deletions src/components/input/input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,26 @@ export function main() {
});
});

it('should have a different ID for outer element and internal input', () => {
return builder
.overrideTemplate(MdInputBaseTestController, `
<md-input id="test-id"></md-input>
`)
.createAsync(MdInputBaseTestController)
.then(fixture => {
fixture.detectChanges();
fakeAsync(() => {
const componentElement: HTMLElement = fixture.debugElement
.query(By.directive(MdInput)).nativeElement;
const inputElement: HTMLInputElement = fixture.debugElement.query(By.css('input'))
.nativeElement;
expect(componentElement.id).toBe('test-id');
expect(inputElement.id).toBeTruthy();
expect(inputElement.id).not.toBe(componentElement.id);
})();
});
});

it('counts characters', () => {
return builder.createAsync(MdInputBaseTestController).then(fixture => {
let instance = fixture.componentInstance;
Expand Down
1 change: 1 addition & 0 deletions src/components/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class MdInput implements ControlValueAccessor, AfterContentInit, OnChange
get characterCount(): number {
return this.empty ? 0 : ('' + this._value).length;
}
get inputId(): string { return `${this.id}-input`; }

/**
* Bindings.
Expand Down

0 comments on commit be5e93a

Please sign in to comment.