Skip to content

Commit 3fb9d66

Browse files
fix: do not set placeholder to empty string by default (#7573) (#7585)
Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
1 parent 0fa4cd8 commit 3fb9d66

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

packages/multi-select-combo-box/src/vaadin-multi-select-combo-box.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
439439
*/
440440
placeholder: {
441441
type: String,
442-
value: '',
443442
observer: '_placeholderChanged',
444443
},
445444

@@ -794,9 +793,12 @@ class MultiSelectComboBox extends ResizeMixin(InputControlMixin(ThemableMixin(El
794793
// Use placeholder for announcing items
795794
if (this._hasValue) {
796795
const tmpPlaceholder = this._mergeItemLabels(selectedItems);
796+
if (this.__tmpA11yPlaceholder === undefined) {
797+
this.__savedPlaceholder = this.placeholder;
798+
}
797799
this.__tmpA11yPlaceholder = tmpPlaceholder;
798800
this.placeholder = tmpPlaceholder;
799-
} else {
801+
} else if (this.__tmpA11yPlaceholder !== undefined) {
800802
delete this.__tmpA11yPlaceholder;
801803
this.placeholder = this.__savedPlaceholder;
802804
}

packages/multi-select-combo-box/test/accessibility.test.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,46 +35,60 @@ describe('accessibility', () => {
3535

3636
describe('placeholder', () => {
3737
beforeEach(() => {
38-
comboBox = fixtureSync(`
39-
<vaadin-multi-select-combo-box
40-
placeholder="Fruits"
41-
></vaadin-multi-select-combo-box>
42-
`);
38+
// Do not use `fixtureSync()` helper to test the case where both placeholder
39+
// and selectedItems are set when the component is initialized, to make sure
40+
// that the placeholder is correctly restored after clearing selectedItems.
41+
comboBox = document.createElement('vaadin-multi-select-combo-box');
42+
comboBox.placeholder = 'Fruits';
4343
comboBox.items = ['Apple', 'Banana', 'Lemon', 'Orange'];
44+
comboBox.selectedItems = ['Apple', 'Banana'];
45+
document.body.appendChild(comboBox);
4446
inputElement = comboBox.inputElement;
4547
});
4648

49+
afterEach(() => {
50+
comboBox.remove();
51+
});
52+
4753
it('should set input placeholder when selected items are changed', () => {
48-
comboBox.selectedItems = ['Apple', 'Banana'];
4954
expect(inputElement.getAttribute('placeholder')).to.equal('Apple, Banana');
5055
});
5156

5257
it('should restore original placeholder when selected items are removed', () => {
53-
comboBox.selectedItems = ['Apple', 'Banana'];
5458
comboBox.selectedItems = [];
5559
expect(inputElement.getAttribute('placeholder')).to.equal('Fruits');
5660
});
5761

5862
it('should keep input placeholder when placeholder property is updated', () => {
59-
comboBox.selectedItems = ['Apple', 'Banana'];
6063
comboBox.placeholder = 'Options';
6164
expect(inputElement.getAttribute('placeholder')).to.equal('Apple, Banana');
6265
});
6366

6467
it('should restore updated placeholder when placeholder property is updated', () => {
65-
comboBox.selectedItems = ['Apple', 'Banana'];
6668
comboBox.placeholder = 'Options';
6769
comboBox.selectedItems = [];
6870
expect(inputElement.getAttribute('placeholder')).to.equal('Options');
6971
});
7072

73+
it('should restore placeholder when selected items are updated and removed', () => {
74+
comboBox.selectedItems = ['Apple'];
75+
comboBox.selectedItems = [];
76+
expect(inputElement.getAttribute('placeholder')).to.equal('Fruits');
77+
});
78+
7179
it('should restore empty placeholder when selected items are removed', () => {
7280
comboBox.placeholder = '';
73-
comboBox.selectedItems = ['Apple', 'Banana'];
7481
comboBox.selectedItems = [];
7582
expect(comboBox.placeholder).to.be.equal('');
7683
expect(inputElement.hasAttribute('placeholder')).to.be.false;
7784
});
85+
86+
it('should clear placeholder when set to undefined and selected items are removed', () => {
87+
comboBox.placeholder = undefined;
88+
comboBox.selectedItems = [];
89+
expect(comboBox.placeholder).to.be.undefined;
90+
expect(inputElement.hasAttribute('placeholder')).to.be.false;
91+
});
7892
});
7993
});
8094

packages/multi-select-combo-box/test/dom/__snapshots__/multi-select-combo-box.test.snap.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
export const snapshots = {};
33

44
snapshots["vaadin-multi-select-combo-box host default"] =
5-
`<vaadin-multi-select-combo-box placeholder="">
5+
`<vaadin-multi-select-combo-box>
66
<label
77
for="input-vaadin-multi-select-combo-box-4"
88
id="label-vaadin-multi-select-combo-box-0"
@@ -38,10 +38,7 @@ snapshots["vaadin-multi-select-combo-box host default"] =
3838
/* end snapshot vaadin-multi-select-combo-box host default */
3939

4040
snapshots["vaadin-multi-select-combo-box host label"] =
41-
`<vaadin-multi-select-combo-box
42-
has-label=""
43-
placeholder=""
44-
>
41+
`<vaadin-multi-select-combo-box has-label="">
4542
<label
4643
for="input-vaadin-multi-select-combo-box-4"
4744
id="label-vaadin-multi-select-combo-box-0"
@@ -79,10 +76,7 @@ snapshots["vaadin-multi-select-combo-box host label"] =
7976
/* end snapshot vaadin-multi-select-combo-box host label */
8077

8178
snapshots["vaadin-multi-select-combo-box host helper"] =
82-
`<vaadin-multi-select-combo-box
83-
has-helper=""
84-
placeholder=""
85-
>
79+
`<vaadin-multi-select-combo-box has-helper="">
8680
<label
8781
for="input-vaadin-multi-select-combo-box-4"
8882
id="label-vaadin-multi-select-combo-box-0"
@@ -128,7 +122,6 @@ snapshots["vaadin-multi-select-combo-box host error"] =
128122
`<vaadin-multi-select-combo-box
129123
has-error-message=""
130124
invalid=""
131-
placeholder=""
132125
>
133126
<label
134127
for="input-vaadin-multi-select-combo-box-4"
@@ -169,10 +162,7 @@ snapshots["vaadin-multi-select-combo-box host error"] =
169162
/* end snapshot vaadin-multi-select-combo-box host error */
170163

171164
snapshots["vaadin-multi-select-combo-box host required"] =
172-
`<vaadin-multi-select-combo-box
173-
placeholder=""
174-
required=""
175-
>
165+
`<vaadin-multi-select-combo-box required="">
176166
<label
177167
for="input-vaadin-multi-select-combo-box-4"
178168
id="label-vaadin-multi-select-combo-box-0"
@@ -212,7 +202,6 @@ snapshots["vaadin-multi-select-combo-box host disabled"] =
212202
`<vaadin-multi-select-combo-box
213203
aria-disabled="true"
214204
disabled=""
215-
placeholder=""
216205
>
217206
<label
218207
for="input-vaadin-multi-select-combo-box-4"
@@ -252,10 +241,7 @@ snapshots["vaadin-multi-select-combo-box host disabled"] =
252241
/* end snapshot vaadin-multi-select-combo-box host disabled */
253242

254243
snapshots["vaadin-multi-select-combo-box host readonly"] =
255-
`<vaadin-multi-select-combo-box
256-
placeholder=""
257-
readonly=""
258-
>
244+
`<vaadin-multi-select-combo-box readonly="">
259245
<label
260246
for="input-vaadin-multi-select-combo-box-4"
261247
id="label-vaadin-multi-select-combo-box-0"
@@ -333,7 +319,6 @@ snapshots["vaadin-multi-select-combo-box host opened default"] =
333319
`<vaadin-multi-select-combo-box
334320
focused=""
335321
opened=""
336-
placeholder=""
337322
>
338323
<label
339324
for="input-vaadin-multi-select-combo-box-4"

0 commit comments

Comments
 (0)