mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 02:06:42 +00:00
Fix icon picker in dialog (#13616)
This commit is contained in:
parent
8c98326e31
commit
f461825a59
@ -13,7 +13,8 @@ type IconItem = {
|
|||||||
icon: string;
|
icon: string;
|
||||||
keywords: string[];
|
keywords: string[];
|
||||||
};
|
};
|
||||||
let iconItems: IconItem[] = [];
|
let iconItems: IconItem[] = [{ icon: "", keywords: [] }];
|
||||||
|
let iconLoaded = false;
|
||||||
|
|
||||||
// eslint-disable-next-line lit/prefer-static-styles
|
// eslint-disable-next-line lit/prefer-static-styles
|
||||||
const rowRenderer: ComboBoxLitRenderer<IconItem> = (item) => html`<mwc-list-item
|
const rowRenderer: ComboBoxLitRenderer<IconItem> = (item) => html`<mwc-list-item
|
||||||
@ -88,15 +89,16 @@ export class HaIconPicker extends LitElement {
|
|||||||
|
|
||||||
private async _openedChanged(ev: PolymerChangedEvent<boolean>) {
|
private async _openedChanged(ev: PolymerChangedEvent<boolean>) {
|
||||||
this._opened = ev.detail.value;
|
this._opened = ev.detail.value;
|
||||||
if (this._opened && !iconItems.length) {
|
if (this._opened && !iconLoaded) {
|
||||||
const iconList = await import("../../build/mdi/iconList.json");
|
const iconList = await import("../../build/mdi/iconList.json");
|
||||||
|
|
||||||
iconItems = iconList.default.map((icon) => ({
|
iconItems = iconList.default.map((icon) => ({
|
||||||
icon: `mdi:${icon.name}`,
|
icon: `mdi:${icon.name}`,
|
||||||
keywords: icon.keywords,
|
keywords: icon.keywords,
|
||||||
}));
|
}));
|
||||||
|
iconLoaded = true;
|
||||||
|
|
||||||
(this.comboBox as any).filteredItems = iconItems;
|
this.comboBox.filteredItems = iconItems;
|
||||||
|
|
||||||
Object.keys(customIcons).forEach((iconSet) => {
|
Object.keys(customIcons).forEach((iconSet) => {
|
||||||
this._loadCustomIconItems(iconSet);
|
this._loadCustomIconItems(iconSet);
|
||||||
@ -116,7 +118,7 @@ export class HaIconPicker extends LitElement {
|
|||||||
keywords: icon.keywords ?? [],
|
keywords: icon.keywords ?? [],
|
||||||
}));
|
}));
|
||||||
iconItems.push(...customIconItems);
|
iconItems.push(...customIconItems);
|
||||||
(this.comboBox as any).filteredItems = iconItems;
|
this.comboBox.filteredItems = iconItems;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.warn(`Unable to load icon list for ${iconsetPrefix} iconset`);
|
console.warn(`Unable to load icon list for ${iconsetPrefix} iconset`);
|
||||||
@ -165,14 +167,12 @@ export class HaIconPicker extends LitElement {
|
|||||||
filteredItems.push(...filteredItemsByKeywords);
|
filteredItems.push(...filteredItemsByKeywords);
|
||||||
|
|
||||||
if (filteredItems.length > 0) {
|
if (filteredItems.length > 0) {
|
||||||
(this.comboBox as any).filteredItems = filteredItems;
|
this.comboBox.filteredItems = filteredItems;
|
||||||
} else {
|
} else {
|
||||||
(this.comboBox as any).filteredItems = [
|
this.comboBox.filteredItems = [{ icon: filterString, keywords: [] }];
|
||||||
{ icon: filterString, keywords: [] },
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(this.comboBox as any).filteredItems = iconItems;
|
this.comboBox.filteredItems = iconItems;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user