Skip to content

Commit 0e99844

Browse files
authored
Fix grid + map editor (#8284)
1 parent 226013d commit 0e99844

File tree

2 files changed

+38
-21
lines changed

2 files changed

+38
-21
lines changed

src/panels/lovelace/editor/config-elements/hui-grid-card-editor.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ export class HuiGridCardEditor extends HuiStackCardEditor {
2929
this._config = config;
3030
}
3131

32+
get _columns(): number {
33+
return this._config!.columns || 3;
34+
}
35+
36+
get _square(): boolean {
37+
return this._config!.square ?? true;
38+
}
39+
3240
protected render(): TemplateResult {
3341
if (!this.hass || !this._config) {
3442
return html``;
@@ -44,7 +52,7 @@ export class HuiGridCardEditor extends HuiStackCardEditor {
4452
"ui.panel.lovelace.editor.card.config.optional"
4553
)})"
4654
type="number"
47-
.value=${(this._config as GridCardConfig).columns}
55+
.value=${this._columns}
4856
.configValue=${"columns"}
4957
@value-changed=${this._handleColumnsChanged}
5058
></paper-input>
@@ -55,7 +63,7 @@ export class HuiGridCardEditor extends HuiStackCardEditor {
5563
.dir=${computeRTLDirection(this.hass)}
5664
>
5765
<ha-switch
58-
.checked=${(this._config as GridCardConfig).square}
66+
.checked=${this._square}
5967
.configValue=${"square"}
6068
@change=${this._handleSquareChanged}
6169
></ha-switch>
@@ -70,24 +78,30 @@ export class HuiGridCardEditor extends HuiStackCardEditor {
7078
if (!this._config) {
7179
return;
7280
}
73-
74-
this._config = {
75-
...this._config,
76-
columns: Number(ev.target.value),
77-
};
81+
const value = Number(ev.target.value);
82+
if (this._columns === value) {
83+
return;
84+
}
85+
if (!ev.target.value) {
86+
this._config = { ...this._config };
87+
delete this._config.columns;
88+
} else {
89+
this._config = {
90+
...this._config,
91+
columns: value,
92+
};
93+
}
7894
fireEvent(this, "config-changed", { config: this._config });
7995
}
8096

8197
private _handleSquareChanged(ev): void {
82-
if (!this._config) {
98+
if (!this._config || this._square === ev.target.checked) {
8399
return;
84100
}
85101

86-
this._config = {
87-
...this._config,
88-
square: ev.target.checked,
89-
};
90-
fireEvent(this, "config-changed", { config: this._config });
102+
fireEvent(this, "config-changed", {
103+
config: { ...this._config, square: ev.target.checked },
104+
});
91105
}
92106
}
93107

src/panels/lovelace/editor/config-elements/hui-map-card-editor.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class HuiMapCardEditor extends LitElement implements LovelaceCardEditor {
7373
}
7474

7575
get _default_zoom(): number {
76-
return this._config!.default_zoom || NaN;
76+
return this._config!.default_zoom || 0;
7777
}
7878

7979
get _geo_location_sources(): string[] {
@@ -199,22 +199,25 @@ export class HuiMapCardEditor extends LitElement implements LovelaceCardEditor {
199199
return;
200200
}
201201
const target = ev.target! as EditorTarget;
202-
let value = ev.detail.value;
203-
204-
if (target.configValue && this[`_${target.configValue}`] === value) {
202+
if (!target.configValue) {
205203
return;
206204
}
207-
if (target.type === "number") {
205+
206+
let value = target.checked ?? ev.detail.value;
207+
208+
if (value && target.type === "number") {
208209
value = Number(value);
209210
}
210-
if (value === "" || (target.type === "number" && isNaN(value))) {
211+
if (this[`_${target.configValue}`] === value) {
212+
return;
213+
}
214+
if (value === "") {
211215
this._config = { ...this._config };
212216
delete this._config[target.configValue!];
213217
} else if (target.configValue) {
214218
this._config = {
215219
...this._config,
216-
[target.configValue]:
217-
target.checked !== undefined ? target.checked : value,
220+
[target.configValue]: value,
218221
};
219222
}
220223
fireEvent(this, "config-changed", { config: this._config });

0 commit comments

Comments
 (0)