diff --git a/src/cdk/text-field/autosize.spec.ts b/src/cdk/text-field/autosize.spec.ts index 66877cf9be9a..eabb88228f97 100644 --- a/src/cdk/text-field/autosize.spec.ts +++ b/src/cdk/text-field/autosize.spec.ts @@ -373,6 +373,13 @@ describe('CdkTextareaAutosize', () => { .withContext('Expected textarea to have a scrollbar.') .toBeLessThan(textarea.scrollHeight); })); + + it('should handle an undefined placeholder', () => { + fixture.componentInstance.placeholder = undefined!; + fixture.detectChanges(); + + expect(textarea.hasAttribute('placeholder')).toBe(false); + }); }); // Styles to reset padding and border to make measurement comparisons easier. diff --git a/src/cdk/text-field/autosize.ts b/src/cdk/text-field/autosize.ts index 3170259f2d64..f07bf93bbddd 100644 --- a/src/cdk/text-field/autosize.ts +++ b/src/cdk/text-field/autosize.ts @@ -100,7 +100,13 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy { } set placeholder(value: string) { this._cachedPlaceholderHeight = undefined; - this._textareaElement.placeholder = value; + + if (value) { + this._textareaElement.setAttribute('placeholder', value); + } else { + this._textareaElement.removeAttribute('placeholder'); + } + this._cacheTextareaPlaceholderHeight(); }