mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(input): setting blank placeholder by default (#10277)
Fixes the `matInput` directive setting the `placeholder` attribute to a blank string by default, causing it to be rendered in the DOM.
This commit is contained in:
committed by
Jeremy Elbourn
parent
c12d7c473e
commit
889a9f25ac
@@ -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: `
|
||||
<mat-form-field>
|
||||
<input matInput>
|
||||
</mat-form-field>
|
||||
`
|
||||
})
|
||||
class MatInputWithoutPlaceholder {
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user