diff --git a/src/lib/input/input.spec.ts b/src/lib/input/input.spec.ts index 101b4509378..34109a29c77 100644 --- a/src/lib/input/input.spec.ts +++ b/src/lib/input/input.spec.ts @@ -71,6 +71,7 @@ describe('MatInput without forms', () => { MatInputOnPush, MatInputWithReadonlyInput, MatInputWithLabelAndPlaceholder, + MatInputWithoutPlaceholder, ], }); @@ -794,6 +795,14 @@ describe('MatInput without forms', () => { expect(container.classList).not.toContain('mat-form-field-hide-placeholder'); }); + it('should not add the `placeholder` attribute if there is no placeholder', () => { + const fixture = TestBed.createComponent(MatInputWithoutPlaceholder); + fixture.detectChanges(); + const input = fixture.debugElement.query(By.css('input')).nativeElement; + + expect(input.hasAttribute('placeholder')).toBe(false); + }); + it('should not show the native placeholder when floatLabel is set to "never"', () => { const fixture = TestBed.createComponent(MatInputWithLabelAndPlaceholder); @@ -1639,3 +1648,13 @@ class MatInputWithAppearance { @ViewChild(MatFormField) formField: MatFormField; appearance: MatFormFieldAppearance; } + +@Component({ + template: ` + + + + ` +}) +class MatInputWithoutPlaceholder { +} diff --git a/src/lib/input/input.ts b/src/lib/input/input.ts index fc8ae24cd26..eb0f757ba41 100644 --- a/src/lib/input/input.ts +++ b/src/lib/input/input.ts @@ -68,7 +68,7 @@ export const _MatInputMixinBase = mixinErrorState(MatInputBase); // Native input properties that are overwritten by Angular inputs need to be synced with // the native input element. Otherwise property bindings for those don't work. '[attr.id]': 'id', - '[placeholder]': 'placeholder', + '[attr.placeholder]': 'placeholder', '[disabled]': 'disabled', '[required]': 'required', '[readonly]': 'readonly', @@ -152,7 +152,7 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl< * Implemented as part of MatFormFieldControl. * @docs-private */ - @Input() placeholder: string = ''; + @Input() placeholder: string; /** * Implemented as part of MatFormFieldControl.