Fix multiselect without data (#4906)

This commit is contained in:
Bram Kragten 2020-02-18 22:17:52 +01:00 committed by GitHub
parent 4675579f79
commit e265d9581c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,6 +41,7 @@ export class HaFormMultiSelect extends LitElement implements HaFormElement {
? this.schema.options ? this.schema.options
: Object.entries(this.schema.options!); : Object.entries(this.schema.options!);
const data = this.data || [];
return html` return html`
<paper-menu-button horizontal-align="right" vertical-offset="8"> <paper-menu-button horizontal-align="right" vertical-offset="8">
<div class="dropdown-trigger" slot="dropdown-trigger"> <div class="dropdown-trigger" slot="dropdown-trigger">
@ -49,7 +50,7 @@ export class HaFormMultiSelect extends LitElement implements HaFormElement {
id="input" id="input"
type="text" type="text"
readonly readonly
value=${this.data value=${data
.map((value) => this.schema.options![value] || value) .map((value) => this.schema.options![value] || value)
.join(", ")} .join(", ")}
label=${this.label} label=${this.label}
@ -68,7 +69,7 @@ export class HaFormMultiSelect extends LitElement implements HaFormElement {
multi multi
slot="dropdown-content" slot="dropdown-content"
attr-for-selected="item-value" attr-for-selected="item-value"
.selectedValues=${this.data} .selectedValues=${data}
@selected-items-changed=${this._valueChanged} @selected-items-changed=${this._valueChanged}
@iron-select=${this._onSelect} @iron-select=${this._onSelect}
> >
@ -79,7 +80,7 @@ export class HaFormMultiSelect extends LitElement implements HaFormElement {
return html` return html`
<paper-icon-item .itemValue=${value}> <paper-icon-item .itemValue=${value}>
<paper-checkbox <paper-checkbox
.checked=${this.data.includes(value)} .checked=${data.includes(value)}
slot="item-icon" slot="item-icon"
></paper-checkbox> ></paper-checkbox>
${this._optionLabel(item)} ${this._optionLabel(item)}