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(input): input element should have a different id from outer element #450

Merged
merged 1 commit into from
May 16, 2016
Merged
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
2 changes: 1 addition & 1 deletion src/components/input/input.html
Original file line number Diff line number Diff line change
@@ -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"
20 changes: 20 additions & 0 deletions src/components/input/input.spec.ts
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions src/components/input/input.ts
Original file line number Diff line number Diff line change
@@ -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.