mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-19 22:47:21 +00:00
Review
This commit is contained in:
@@ -170,7 +170,11 @@ export class HaGenericPicker extends LitElement {
|
|||||||
type="button"
|
type="button"
|
||||||
class=${this._opened ? "opened" : ""}
|
class=${this._opened ? "opened" : ""}
|
||||||
compact
|
compact
|
||||||
.unknown=${this._unknownValue(this.value, this.getItems())}
|
.unknown=${this._unknownValue(
|
||||||
|
this.allowCustomValue,
|
||||||
|
this.value,
|
||||||
|
this.getItems()
|
||||||
|
)}
|
||||||
.unknownItemText=${this.unknownItemText}
|
.unknownItemText=${this.unknownItemText}
|
||||||
aria-label=${ifDefined(this.label)}
|
aria-label=${ifDefined(this.label)}
|
||||||
@click=${this.open}
|
@click=${this.open}
|
||||||
@@ -253,9 +257,13 @@ export class HaGenericPicker extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _unknownValue = memoizeOne(
|
private _unknownValue = memoizeOne(
|
||||||
(value?: string, items?: (PickerComboBoxItem | string)[]) => {
|
(
|
||||||
|
allowCustomValue: boolean,
|
||||||
|
value?: string,
|
||||||
|
items?: (PickerComboBoxItem | string)[]
|
||||||
|
) => {
|
||||||
if (
|
if (
|
||||||
this.allowCustomValue ||
|
allowCustomValue ||
|
||||||
value === undefined ||
|
value === undefined ||
|
||||||
value === null ||
|
value === null ||
|
||||||
value === "" ||
|
value === "" ||
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export class HaNavigationPicker extends LitElement {
|
|||||||
this._loadNavigationItems();
|
this._loadNavigationItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _navigationItems?: PickerComboBoxItem[];
|
private _navigationItems: PickerComboBoxItem[] = [];
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
return html`
|
return html`
|
||||||
@@ -53,9 +53,7 @@ export class HaNavigationPicker extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _valueRenderer = (itemId: string) => {
|
private _valueRenderer = (itemId: string) => {
|
||||||
const item = this._navigationItems!.find(
|
const item = this._navigationItems.find((navItem) => navItem.id === itemId);
|
||||||
(navItem) => navItem.id === itemId
|
|
||||||
);
|
|
||||||
return html`
|
return html`
|
||||||
${item?.icon
|
${item?.icon
|
||||||
? html`<ha-icon slot="start" .icon=${item.icon}></ha-icon>`
|
? html`<ha-icon slot="start" .icon=${item.icon}></ha-icon>`
|
||||||
@@ -67,7 +65,7 @@ export class HaNavigationPicker extends LitElement {
|
|||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
private _getItems = () => this._navigationItems!;
|
private _getItems = () => this._navigationItems;
|
||||||
|
|
||||||
private async _loadNavigationItems() {
|
private async _loadNavigationItems() {
|
||||||
const panels = Object.entries(this.hass!.panels).map(([id, panel]) => ({
|
const panels = Object.entries(this.hass!.panels).map(([id, panel]) => ({
|
||||||
@@ -119,7 +117,7 @@ export class HaNavigationPicker extends LitElement {
|
|||||||
const viewPath = `/${panel.url_path}/${view.path ?? index}`;
|
const viewPath = `/${panel.url_path}/${view.path ?? index}`;
|
||||||
const viewPrimary =
|
const viewPrimary =
|
||||||
view.title ?? (view.path ? titleCase(view.path) : `${index}`);
|
view.title ?? (view.path ? titleCase(view.path) : `${index}`);
|
||||||
this._navigationItems!.push({
|
this._navigationItems.push({
|
||||||
id: viewPath,
|
id: viewPath,
|
||||||
secondary: viewPath,
|
secondary: viewPath,
|
||||||
icon: view.icon ?? "mdi:view-compact",
|
icon: view.icon ?? "mdi:view-compact",
|
||||||
|
|||||||
@@ -191,10 +191,11 @@ export class HaPickerComboBox extends ScrollableFadeMixin(LitElement) {
|
|||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
const searchLabel =
|
const searchLabel =
|
||||||
(this.label ?? this.allowCustomValue)
|
this.label ??
|
||||||
|
(this.allowCustomValue
|
||||||
? (this.hass?.localize("ui.components.combo-box.search_or_custom") ??
|
? (this.hass?.localize("ui.components.combo-box.search_or_custom") ??
|
||||||
"Search | Add custom value")
|
"Search | Add custom value")
|
||||||
: (this.hass?.localize("ui.common.search") ?? "Search");
|
: (this.hass?.localize("ui.common.search") ?? "Search"));
|
||||||
|
|
||||||
return html`<ha-textfield
|
return html`<ha-textfield
|
||||||
.label=${searchLabel}
|
.label=${searchLabel}
|
||||||
|
|||||||
Reference in New Issue
Block a user