Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions src/cdk/text-field/autosize.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion src/cdk/text-field/autosize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down