mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +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 { customElement, property } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
@ -26,6 +26,17 @@ export class HaNumberSelector extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
@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() {
|
protected render() {
|
||||||
const isBox = this.selector.number?.mode === "box";
|
const isBox = this.selector.number?.mode === "box";
|
||||||
|
|
||||||
@ -64,7 +75,7 @@ export class HaNumberSelector extends LitElement {
|
|||||||
class=${classMap({ single: this.selector.number?.mode === "box" })}
|
class=${classMap({ single: this.selector.number?.mode === "box" })}
|
||||||
.min=${this.selector.number?.min}
|
.min=${this.selector.number?.min}
|
||||||
.max=${this.selector.number?.max}
|
.max=${this.selector.number?.max}
|
||||||
.value=${this.value ?? ""}
|
.value=${this._valueStr ?? ""}
|
||||||
.step=${this.selector.number?.step ?? 1}
|
.step=${this.selector.number?.step ?? 1}
|
||||||
helperPersistent
|
helperPersistent
|
||||||
.helper=${isBox ? this.helper : undefined}
|
.helper=${isBox ? this.helper : undefined}
|
||||||
@ -86,6 +97,7 @@ export class HaNumberSelector extends LitElement {
|
|||||||
|
|
||||||
private _handleInputChange(ev) {
|
private _handleInputChange(ev) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
this._valueStr = ev.target.value;
|
||||||
const value =
|
const value =
|
||||||
ev.target.value === "" || isNaN(ev.target.value)
|
ev.target.value === "" || isNaN(ev.target.value)
|
||||||
? undefined
|
? undefined
|
||||||
|
Loading…
x
Reference in New Issue
Block a user