mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 07:16:39 +00:00
Fix handling of negative zero in number selectors (#17127)
This commit is contained in:
parent
63095f1501
commit
ae35fd1eb8
@ -1,4 +1,4 @@
|
||||
import { css, CSSResultGroup, html, LitElement } from "lit";
|
||||
import { css, CSSResultGroup, html, LitElement, PropertyValues } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
@ -26,6 +26,17 @@ export class HaNumberSelector extends LitElement {
|
||||
|
||||
@property({ type: Boolean }) public disabled = false;
|
||||
|
||||
private _valueStr = "";
|
||||
|
||||
protected willUpdate(changedProps: PropertyValues) {
|
||||
if (changedProps.has("value")) {
|
||||
if (this.value !== Number(this._valueStr)) {
|
||||
this._valueStr =
|
||||
!this.value || isNaN(this.value) ? "" : this.value.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
const isBox = this.selector.number?.mode === "box";
|
||||
|
||||
@ -64,7 +75,7 @@ export class HaNumberSelector extends LitElement {
|
||||
class=${classMap({ single: this.selector.number?.mode === "box" })}
|
||||
.min=${this.selector.number?.min}
|
||||
.max=${this.selector.number?.max}
|
||||
.value=${this.value ?? ""}
|
||||
.value=${this._valueStr ?? ""}
|
||||
.step=${this.selector.number?.step ?? 1}
|
||||
helperPersistent
|
||||
.helper=${isBox ? this.helper : undefined}
|
||||
@ -86,6 +97,7 @@ export class HaNumberSelector extends LitElement {
|
||||
|
||||
private _handleInputChange(ev) {
|
||||
ev.stopPropagation();
|
||||
this._valueStr = ev.target.value;
|
||||
const value =
|
||||
ev.target.value === "" || isNaN(ev.target.value)
|
||||
? undefined
|
||||
|
Loading…
x
Reference in New Issue
Block a user