Skip to content

Commit

Permalink
fix: don't apply placeholder styles to an empty value item (#2877)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki authored Oct 15, 2021
1 parent 7cbdc3e commit 2ea0415
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/select/src/vaadin-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,13 @@ class Select extends DelegateFocusMixin(FieldMixin(SlotMixin(ElementMixin(Themab

const selected = this._items[this._menuElement.selected];

this._valueButton.removeAttribute('placeholder');

if (!selected) {
if (this.placeholder) {
const item = this.__createItem(this.placeholder);
this.__appendItem(item);
this._valueButton.setAttribute('placeholder', '');
}
} else {
this.__attachSelectedItem(selected);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions packages/select/test/visual/lumo/select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,17 @@ describe('select', () => {
element.value = 'item 1';
await visualDiff(div, 'width-value');
});

it('empty value', async () => {
// To make sure placeholder styles aren't applied to empty value item
element.placeholder = 'Placeholder';
element.renderer = (root) => {
root.innerHTML = `
<vaadin-list-box>
<vaadin-item value="">Empty</vaadin-item>
</vaadin-list-box>
`;
};
await visualDiff(div, 'empty-value');
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions packages/select/test/visual/material/select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,17 @@ describe('select', () => {
element.value = 'item 1';
await visualDiff(div, 'width-value');
});

it('empty value', async () => {
// To make sure placeholder styles aren't applied to empty value item
element.placeholder = 'Placeholder';
element.renderer = (root) => {
root.innerHTML = `
<vaadin-list-box>
<vaadin-item value="">Empty</vaadin-item>
</vaadin-list-box>
`;
};
await visualDiff(div, 'empty-value');
});
});
4 changes: 2 additions & 2 deletions packages/select/theme/lumo/vaadin-select-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const select = css`
}
/* placeholder styles */
:host(:not([has-value])) [part='input-field'] ::slotted([slot='value']) {
:host [part='input-field'] ::slotted([slot='value'][placeholder]) {
color: inherit;
transition: opacity 0.175s 0.1s;
opacity: 0.5;
}
:host([has-value]) [part='input-field'] ::slotted([slot='value']) {
:host [part='input-field'] ::slotted([slot='value']) {
color: var(--lumo-body-text-color);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/select/theme/material/vaadin-select-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ const select = css`
}
/* placeholder styles */
:host(:not([has-value])) [part='input-field'] ::slotted([slot='value']) {
:host [part='input-field'] ::slotted([slot='value'][placeholder]) {
color: var(--material-disabled-text-color);
transition: opacity 0.175s 0.1s;
opacity: 1;
}
:host([has-value]) [part='input-field'] ::slotted([slot='value']) {
:host [part='input-field'] ::slotted([slot='value']) {
color: var(--material-body-text-color);
}
Expand Down

0 comments on commit 2ea0415

Please sign in to comment.