Skip to content

Commit acb0bd0

Browse files
crisbetoandrewseguin
authored andcommitted
fix(chips): unable to bind to chip input placeholder (#10855)
Fixes the value that is bound to the `placeholder` input not being assigned to the `placeholder` attribute. Fixes #10848.
1 parent 4ae63b3 commit acb0bd0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/lib/chips/chip-input.spec.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ describe('MatChipInput', () => {
1616
let inputDebugElement: DebugElement;
1717
let inputNativeElement: HTMLElement;
1818
let chipInputDirective: MatChipInput;
19-
2019
let dir = 'ltr';
2120

2221
beforeEach(async(() => {
@@ -56,6 +55,15 @@ describe('MatChipInput', () => {
5655
it('should have a default id', () => {
5756
expect(inputNativeElement.getAttribute('id')).toBeTruthy();
5857
});
58+
59+
it('should allow binding to the `placeholder` input', () => {
60+
expect(inputNativeElement.hasAttribute('placeholder')).toBe(false);
61+
62+
testChipInput.placeholder = 'bound placeholder';
63+
fixture.detectChanges();
64+
65+
expect(inputNativeElement.getAttribute('placeholder')).toBe('bound placeholder');
66+
});
5967
});
6068

6169
describe('[addOnBlur]', () => {
@@ -142,11 +150,13 @@ describe('MatChipInput', () => {
142150
</mat-chip-list>
143151
<input matInput [matChipInputFor]="chipList"
144152
[matChipInputAddOnBlur]="addOnBlur"
145-
(matChipInputTokenEnd)="add($event)" />
153+
(matChipInputTokenEnd)="add($event)"
154+
[placeholder]="placeholder" />
146155
`
147156
})
148157
class TestChipInput {
149158
addOnBlur: boolean = false;
159+
placeholder = '';
150160

151161
add(_: MatChipInputEvent) {
152162
}

src/lib/chips/chip-input.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ let nextUniqueId = 0;
3838
'(focus)': '_focus()',
3939
'(input)': '_onInput()',
4040
'[id]': 'id',
41+
'[attr.placeholder]': 'placeholder || null',
4142
}
4243
})
4344
export class MatChipInput {
@@ -75,7 +76,11 @@ export class MatChipInput {
7576
@Output('matChipInputTokenEnd')
7677
chipEnd: EventEmitter<MatChipInputEvent> = new EventEmitter<MatChipInputEvent>();
7778

78-
/** The input's placeholder text. */
79+
/**
80+
* The input's placeholder text.
81+
* @deprecated Bind to the `placeholder` attribute directly.
82+
* @deletion-target 7.0.0
83+
*/
7984
@Input() placeholder: string = '';
8085

8186
/** Unique id for the input. */

0 commit comments

Comments
 (0)